SystemTrayMenu/Config/Config.cs
Markus Hofknecht d1b8c0b279 #88, #69, #103, #104, #105, #97, #106 ,version 0.10.2.8
[Feature] Code Analyze and Refactor 0.11 (#88)
[Feature] Mouse disturbing while using keys (#69)
[Feature] Reload menu when reenter or click (#103)
[BUG] Crash when fast mouse movings (#104)
[BUG] Loading was shown too often (#105)
[BUG] submenu wrong location in edgecase (#97)
[BUG] Folder shown as open (green) but is not open (#106)
2020-06-20 17:38:21 +02:00

93 lines
2.9 KiB
C#

using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using SystemTrayMenu.UserInterface.FolderDialog;
using SystemTrayMenu.Utilities;
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)
{
string textFirstStart = Translator.GetText("TextFirstStart");
MessageBox.Show(textFirstStart, Translator.GetText("SystemTrayMenu"),
MessageBoxButtons.OK);
ShowHelpFAQ();
pathOK = SetFolderByUser();
}
return pathOK;
}
public static bool SetFolderByUser(bool save = true)
{
bool pathOK = false;
bool userAborted = false;
using (FolderDialog dialog = new FolderDialog())
{
dialog.InitialFolder = Path;
do
{
if (dialog.ShowDialog() == DialogResult.OK)
{
if (Directory.Exists(dialog.Folder))
{
pathOK = true;
Properties.Settings.Default.PathDirectory =
dialog.Folder;
if (save)
{
Properties.Settings.Default.Save();
}
}
}
else
{
userAborted = true;
}
}
while (!pathOK && !userAborted);
};
return pathOK;
}
internal static void ShowHelpFAQ()
{
string browserPath = FileUrl.GetDefaultBrowserPath();
if (!string.IsNullOrEmpty(browserPath))
{
Process.Start(browserPath, "https://github.com/Hofknecht/SystemTrayMenu#FAQ");
}
}
}
}