-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to change local library folder
- Loading branch information
Showing
5 changed files
with
80 additions
and
26 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Robots; | ||
|
||
public record Settings(string LocalLibraryPath) | ||
{ | ||
/// <summary> | ||
/// Win: C:\Users\userName\AppData\Roaming\McNeel\Rhinoceros\packages\7.0\Robots\libraries | ||
/// Mac: /Users/userName/.config/McNeel/Rhinoceros/packages/7.0/Robots/libraries | ||
/// Lib: {appData}\Robots\libraries | ||
/// </summary> | ||
public static string PluginPath | ||
{ | ||
get | ||
{ | ||
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify); | ||
int version = 7; | ||
#if NET48 | ||
version = Rhino.RhinoApp.Version.Major; | ||
#endif | ||
#if (NET48 || DEBUG) | ||
return Path.Combine(appData, "McNeel", "Rhinoceros", "packages", $"{version:0.0}", "Robots"); | ||
#elif NETSTANDARD2_0 | ||
return Path.Combine(appData, "Robots"); | ||
#endif | ||
} | ||
} | ||
|
||
static string SettingsPath => Path.Combine(PluginPath, "settings.json"); | ||
|
||
static Settings GetDefault() | ||
{ | ||
var localLibraryPath = | ||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Robots"); | ||
|
||
return new(localLibraryPath); | ||
} | ||
|
||
public static Settings Load() | ||
{ | ||
if (!File.Exists(SettingsPath)) | ||
return GetDefault(); | ||
|
||
var json = File.ReadAllText(SettingsPath); | ||
var settings = JsonConvert.DeserializeObject<Settings>(json) | ||
?? throw new(" Could not load settings file."); | ||
|
||
return settings; | ||
} | ||
|
||
public static void Save(Settings settings) | ||
{ | ||
var json = JsonConvert.SerializeObject(settings, Formatting.Indented); | ||
File.WriteAllText(SettingsPath, json); | ||
} | ||
} |