2020-06-21 03:38:21 +12:00
|
|
|
|
using System.Diagnostics;
|
2020-03-28 08:43:16 +13:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
2020-05-31 23:43:12 +12:00
|
|
|
|
using System.Windows.Forms;
|
2020-06-06 02:42:12 +12:00
|
|
|
|
using SystemTrayMenu.UserInterface.FolderDialog;
|
2020-03-28 12:42:32 +13:00
|
|
|
|
using SystemTrayMenu.Utilities;
|
2020-03-28 08:43:16 +13:00
|
|
|
|
|
|
|
|
|
namespace SystemTrayMenu
|
|
|
|
|
{
|
|
|
|
|
public static class Config
|
|
|
|
|
{
|
|
|
|
|
public const string Language = "en";
|
|
|
|
|
|
|
|
|
|
public static string Path => Properties.Settings.Default.PathDirectory;
|
|
|
|
|
|
|
|
|
|
public static void UpgradeIfNotUpgraded()
|
|
|
|
|
{
|
|
|
|
|
if (!Properties.Settings.Default.IsUpgraded)
|
|
|
|
|
{
|
|
|
|
|
// configs located at "%localappdata%\<AssemblyCompany>\"
|
|
|
|
|
Properties.Settings.Default.Upgrade();
|
|
|
|
|
|
|
|
|
|
Properties.Settings.Default.IsUpgraded = true;
|
|
|
|
|
Properties.Settings.Default.Save();
|
|
|
|
|
|
|
|
|
|
FileVersionInfo versionInfo = FileVersionInfo.
|
|
|
|
|
GetVersionInfo(Assembly.GetEntryAssembly().Location);
|
|
|
|
|
Log.Info($"Settings upgraded from " +
|
|
|
|
|
$"%localappdata%\\{versionInfo.CompanyName}\\");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool LoadOrSetByUser()
|
|
|
|
|
{
|
|
|
|
|
bool pathOK = Directory.Exists(
|
|
|
|
|
Properties.Settings.Default.PathDirectory);
|
|
|
|
|
|
|
|
|
|
if (!pathOK)
|
|
|
|
|
{
|
2020-05-31 23:43:12 +12:00
|
|
|
|
string textFirstStart = Translator.GetText("TextFirstStart");
|
|
|
|
|
MessageBox.Show(textFirstStart, Translator.GetText("SystemTrayMenu"),
|
|
|
|
|
MessageBoxButtons.OK);
|
|
|
|
|
ShowHelpFAQ();
|
2020-03-28 08:43:16 +13:00
|
|
|
|
pathOK = SetFolderByUser();
|
|
|
|
|
}
|
|
|
|
|
return pathOK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 05:43:47 +12:00
|
|
|
|
public static bool SetFolderByUser(bool save = true)
|
2020-03-28 08:43:16 +13:00
|
|
|
|
{
|
|
|
|
|
bool pathOK = false;
|
|
|
|
|
bool userAborted = false;
|
2020-06-06 02:42:12 +12:00
|
|
|
|
using (FolderDialog dialog = new FolderDialog())
|
2020-03-28 08:43:16 +13:00
|
|
|
|
{
|
2020-06-06 02:42:12 +12:00
|
|
|
|
dialog.InitialFolder = Path;
|
2020-03-28 08:43:16 +13:00
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2020-06-06 02:42:12 +12:00
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
2020-03-28 08:43:16 +13:00
|
|
|
|
{
|
2020-06-06 02:42:12 +12:00
|
|
|
|
if (Directory.Exists(dialog.Folder))
|
2020-03-28 08:43:16 +13:00
|
|
|
|
{
|
|
|
|
|
pathOK = true;
|
|
|
|
|
Properties.Settings.Default.PathDirectory =
|
2020-06-06 02:42:12 +12:00
|
|
|
|
dialog.Folder;
|
2020-05-05 05:43:47 +12:00
|
|
|
|
if (save)
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.Save();
|
|
|
|
|
}
|
2020-03-28 08:43:16 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
userAborted = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (!pathOK && !userAborted);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return pathOK;
|
|
|
|
|
}
|
2020-05-31 23:43:12 +12:00
|
|
|
|
|
|
|
|
|
internal static void ShowHelpFAQ()
|
|
|
|
|
{
|
2020-06-06 02:42:12 +12:00
|
|
|
|
string browserPath = FileUrl.GetDefaultBrowserPath();
|
2020-06-06 23:46:12 +12:00
|
|
|
|
if (!string.IsNullOrEmpty(browserPath))
|
2020-06-06 02:42:12 +12:00
|
|
|
|
{
|
|
|
|
|
Process.Start(browserPath, "https://github.com/Hofknecht/SystemTrayMenu#FAQ");
|
|
|
|
|
}
|
2020-05-31 23:43:12 +12:00
|
|
|
|
}
|
2020-03-28 08:43:16 +13:00
|
|
|
|
}
|
|
|
|
|
}
|