Skip to content

Commit

Permalink
Save to Document/Decal Plugins instead of Program Files
Browse files Browse the repository at this point in the history
  • Loading branch information
amoeba committed May 25, 2020
1 parent df4de93 commit 12f7add
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions PluginCore.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;

using System.Net;
using System.IO;

using Decal.Adapter;
using Decal.Adapter.Wrappers;

Expand All @@ -21,15 +22,16 @@ protected override void Startup()
{
try
{
Logging.Init(Path.ToString() + "\\messages.txt", Path.ToString() + "\\errors.txt");
string dir = setupPluginDir();
Logging.Init(dir + "\\messages.txt", dir + "\\errors.txt");

MyHost = Host;
MyCore = Core;

// Plugin setup
Account.Init(MyCore);
Character.Init(MyCore, MyHost);
Settings.Init(Path.ToString() + "\\settings.txt");
Settings.Init(dir + "\\settings.txt");
Util.Init(MyHost);
Settings.Load();
MainView.ViewInit(Path.ToString() + "//icon.bmp");
Expand Down Expand Up @@ -74,6 +76,49 @@ protected override void Shutdown()
}
}

/**
* Attempt to find a suitable place to store log and setting files and ensure
* that directory exists.
*
* Falls back to the same folder as the TreeStats DLL.
*/
string setupPluginDir()
{
string dir = null;

try {
dir = string.Format(@"{0}\{1}\{2}",
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"Decal Plugins",
"TreeStats");

Directory.CreateDirectory(dir);
}
catch (Exception ex)
{
// noop
}
finally
{
if (dir == null)
{
dir = Path;
}
}

try
{
if (!Directory.Exists(dir))
{
dir = Path;
}
} catch (Exception ex)
{
// noop
}

return dir;
}
void CharacterFilter_LoginComplete(object sender, EventArgs e)
{
try
Expand Down

0 comments on commit 12f7add

Please sign in to comment.