-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
1,486 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to Spectre Systems AB under one or more agreements. | ||
// Spectre Systems AB licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Jarvis.Addin.Files | ||
{ | ||
internal sealed class Constants | ||
{ | ||
internal sealed class Settings | ||
{ | ||
public const string Version = "Files.Version"; | ||
|
||
internal sealed class Include | ||
{ | ||
public const string Folders = "Files.Include.Folders"; | ||
public const string Extensions = "Files.Include.Extensions"; | ||
} | ||
|
||
internal sealed class Exclude | ||
{ | ||
public const string Folders = "Files.Exclude.Folders"; | ||
public const string Patterns = "Files.Exclude.Patterns"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Licensed to Spectre Systems AB under one or more agreements. | ||
// Spectre Systems AB licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Jarvis.Core; | ||
using Spectre.System.IO; | ||
|
||
namespace Jarvis.Addin.Files | ||
{ | ||
internal sealed class FileSettings | ||
{ | ||
public int Version { get; set; } | ||
public HashSet<DirectoryPath> IncludedFolders { get; } | ||
public HashSet<string> IncludedExtensions { get; } | ||
public HashSet<DirectoryPath> ExcludedFolders { get; } | ||
public HashSet<string> ExcludedPatterns { get; } | ||
|
||
public const int CurrentVersion = 1; | ||
|
||
public FileSettings() | ||
{ | ||
IncludedFolders = new HashSet<DirectoryPath>(new PathComparer(false)); | ||
IncludedExtensions = new HashSet<string>(StringComparer.Ordinal); | ||
ExcludedFolders = new HashSet<DirectoryPath>(new PathComparer(false)); | ||
ExcludedPatterns = new HashSet<string>(StringComparer.Ordinal); | ||
} | ||
|
||
public static FileSettings Load(ISettingsStore settings) | ||
{ | ||
var model = new FileSettings | ||
{ | ||
Version = settings.Get<int>(Constants.Settings.Version) | ||
}; | ||
|
||
// Load included folders. | ||
var includeFolders = settings.Get<string>(Constants.Settings.Include.Folders); | ||
if (includeFolders != null) | ||
{ | ||
model.IncludedFolders.AddRange(includeFolders | ||
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) | ||
.Select(s => new DirectoryPath(s))); | ||
} | ||
|
||
// Load included extensions. | ||
var includeExtensions = settings.Get<string>(Constants.Settings.Include.Extensions); | ||
if (!string.IsNullOrWhiteSpace(includeExtensions)) | ||
{ | ||
model.IncludedExtensions.AddRange(includeExtensions.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); | ||
} | ||
|
||
// Load excluded folders. | ||
var excludeFolders = settings.Get<string>(Constants.Settings.Exclude.Folders); | ||
if (excludeFolders != null) | ||
{ | ||
model.ExcludedFolders.AddRange(excludeFolders | ||
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) | ||
.Select(s => new DirectoryPath(s))); | ||
} | ||
|
||
// Load excluded patterns. | ||
var excludePatterns = settings.Get<string>(Constants.Settings.Exclude.Patterns); | ||
if (!string.IsNullOrWhiteSpace(excludePatterns)) | ||
{ | ||
model.ExcludedPatterns.AddRange(excludePatterns.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); | ||
} | ||
|
||
return model; | ||
} | ||
|
||
public void Save(ISettingsStore settings) | ||
{ | ||
settings.Set(Constants.Settings.Version, CurrentVersion); | ||
settings.Set(Constants.Settings.Include.Folders, string.Join("|", IncludedFolders.Select(p => p.FullPath))); | ||
settings.Set(Constants.Settings.Include.Extensions, string.Join("|", IncludedExtensions)); | ||
settings.Set(Constants.Settings.Exclude.Folders, string.Join("|", ExcludedFolders.Select(p => p.FullPath))); | ||
settings.Set(Constants.Settings.Exclude.Patterns, string.Join("|", ExcludedPatterns)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to Spectre Systems AB under one or more agreements. | ||
// Spectre Systems AB licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Jarvis.Core; | ||
using Spectre.System.IO; | ||
|
||
namespace Jarvis.Addin.Files | ||
{ | ||
internal sealed class FileSettingsSeeder : ISettingsSeeder | ||
{ | ||
public void Seed(ISettingsStore store) | ||
{ | ||
var model = FileSettings.Load(store); | ||
|
||
if (model.Version == 0) | ||
{ | ||
Initialize(model); | ||
model.Save(store); | ||
} | ||
} | ||
|
||
private static void Initialize(FileSettings model) | ||
{ | ||
// Included folders. | ||
model.IncludedFolders.Add(new DirectoryPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))); | ||
model.IncludedFolders.Add(new DirectoryPath(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic))); | ||
model.IncludedFolders.Add(new DirectoryPath(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos))); | ||
model.IncludedFolders.Add(new DirectoryPath(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures))); | ||
|
||
// Included extensions. | ||
model.IncludedExtensions.AddRange(new[] | ||
{ | ||
"ai", "avi", "doc", "docx", "eps", "flv", "gif", "htm", "html", | ||
"jpeg", "jpg", "mov", "mp3", "mp4", "mpg", "mpeg", "odt", "ogg", "ogv", "pdf", "png", "ppt", "psd", | ||
"rar", "rtf", "svg", "txt", "wav", "wma", "xls", "xlsx", "zip" | ||
}); | ||
|
||
// Excluded patterns. | ||
model.ExcludedPatterns.AddRange(new[] { ".git", "node_modules", "packages" }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.