Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
1. Sure, you can use the FileSystemWatcher class to watch just the settings file and trigger an event which reloads S+. Add this script to Global Actions > Load/Unload > Load: Code://Only install this watcher in the last script engine pool so it's not running multiple instances
if(__spEngineWrapper.Engine.Name == sp.EngineList().Last().Engine.Name)
{
var configWatcher = new clr.System.IO.FileSystemWatcher();
//Set the path to the default S+ config file location, change if needed
configWatcher.Path = clr.System.IO.Path.Combine(clr.System.Environment.GetFolderPath(clr.System.Environment.SpecialFolder.ApplicationData), "StrokesPlus.net");
//Only watch the S+ config file, no others in the directory
configWatcher.Filter = "StrokesPlus.net.bin";
//Only subscribe to file write operations
configWatcher.NotifyFilter = clr.System.IO.NotifyFilters.LastWrite;
//Create the event handler which is called when the file changes
var configChangedEvent = configWatcher.Changed.connect(
function (sender, fileChangedEvent) {
//Create a timer when the file is changed, to wait 1 second, clean up, and reload S+
sp.CreateTimer("ConfigReload",
1000,
0,
` sp.GetStoredObject("ConfigChangedEvent").disconnect();
sp.GetStoredObject("ConfigWatcher").Dispose();
sp.DeleteStoredObject("ConfigWatcher");
sp.Reload();
`);
}
);
//Start the file watcher
configWatcher.EnableRaisingEvents = true;
//Store the file watcher and Changed event objects so the timer can access them
sp.StoreObject("ConfigChangedEvent", configChangedEvent);
sp.StoreObject("ConfigWatcher", configWatcher);
}
2. Ugh, that is a pickle. So the settings object (sp_config in scripts) is just a .NET class/object, so there's nothing proprietary going on. I put this plug-in together to export the object to JSON, it looks like the output file is complete, but I cannot guarantee it 100% https://www.strokesplus.net/files/SettingsJSONExport.zipNOTE: Extract this with 7-Zip or if using Windows, right-click the DLL after you extract it and uncheck the blocked or whatever box so Windows will trust/allow it to load. Then open S+ and go to the Plug-Ins section and click Add Plug-In... under the Search Locations tab. Finally, make a temp action to call the script below, the script below assumes the StrokesPlus.net.bin file is in the standard install location, so change as needed. The first param is the location of the config file, the second is where to save the json file. Note: This assumes you do not have a password set via the tray icon (Set Password...). If you do have that, clear the password (leave new password fields blank) until you finish the export. Code:var configFolder = clr.System.Environment.GetFolderPath(clr.System.Environment.SpecialFolder.ApplicationData) + "\\StrokesPlus.net";
SettingsJSONExport.Export(configFolder + "\\StrokesPlus.net.bin", configFolder + "\\StrokesPlus.net.json");
Once you have your JSON files from each config, you can compare as needed, though reconciliation might be tedious. However, there are JSON compare websites out there and read the section below as if you're adept at C# you could handle it programmatically (though I'd suspect it would be quicker to just manually handle the necessary differences).
By the way, if you're familiar with C# it's very easy to make plug-ins. In this case it was super easy as I already built-in a JSON export function, but trying to deserialize the JSON back into the Settings class object blew up so I don't use it. Create a new C# .NET Framework Library Class, select .NET version 4.6.2, then under References, click Add and browse to StrokesPlus.net.exe to access the public classes/etc. Below is the entirety of this plug-ins code. Note that you don't need to reference StrokesPlus.net.exe unless you're trying to access something specific internally - in fact I don't generally recommend it because I don't consider those classes/etc to be something for which I maintain compatibility as they're really internal things. But in this case, it makes sense. Code:using StrokesPlus.net.Code;
namespace SettingsJSONExport
{
public static class SettingsJSONExport
{
public static void Export(string configPath, string jsonPath)
{
var config = SettingsReader.ReadFromBinaryFile<Settings>(configPath, true);
SettingsReader.WriteToJSONFile<Settings>(jsonPath, config);
}
}
}
|