[BUG] autostart activate not always working #28

https://github.com/Hofknecht/SystemTrayMenu/issues/28
This commit is contained in:
Markus Hofknecht 2019-07-08 18:56:31 +02:00
parent 47bba47ea4
commit 87e00358ed
6 changed files with 90 additions and 60 deletions

127
Config.cs
View file

@ -1,59 +1,70 @@
using Microsoft.WindowsAPICodePack.Dialogs; using Microsoft.WindowsAPICodePack.Dialogs;
using System; using System.IO;
using System.IO;
namespace SystemTrayMenu
namespace SystemTrayMenu {
{ public class Config
public class Config {
{ public static string Language = "en";
public static string Language = "en";
public static string Path
public static string Path
{
get
{
return Properties.Settings.Default.PathDirectory;
}
}
public static bool LoadOrSetByUser()
{ {
Properties.Settings.Default.Upgrade(); // configs located at "%localappdata%\<AssemblyCompany>\" get
bool pathOK = Directory.Exists(Properties.Settings.Default.PathDirectory); {
if (!pathOK) return Properties.Settings.Default.PathDirectory;
{ }
pathOK = SetFolderByUser(); }
}
return pathOK; public static void UpgradeIfNotUpgraded()
} {
if (!Properties.Settings.Default.IsUpgraded)
public static bool SetFolderByUser() {
{ // configs located at "%localappdata%\<AssemblyCompany>\"
bool pathOK = false; Properties.Settings.Default.Upgrade();
bool userAborted = false; Properties.Settings.Default.IsUpgraded = true;
CommonOpenFileDialog dialog = new CommonOpenFileDialog(); Properties.Settings.Default.Save();
dialog.InitialDirectory = Path; }
dialog.IsFolderPicker = true; }
do
{ public static bool LoadOrSetByUser()
if (dialog.ShowDialog() == CommonFileDialogResult.Ok) {
{ bool pathOK = Directory.Exists(
if (Directory.Exists(dialog.FileName)) Properties.Settings.Default.PathDirectory);
{
pathOK = true; if (!pathOK)
Properties.Settings.Default.PathDirectory = {
dialog.FileName; pathOK = SetFolderByUser();
Properties.Settings.Default.Save(); }
} return pathOK;
} }
else
{ public static bool SetFolderByUser()
userAborted = true; {
} bool pathOK = false;
} bool userAborted = false;
while (!pathOK && !userAborted); CommonOpenFileDialog dialog = new CommonOpenFileDialog();
dialog.InitialDirectory = Path;
return pathOK; dialog.IsFolderPicker = true;
} do
} {
} if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
{
if (Directory.Exists(dialog.FileName))
{
pathOK = true;
Properties.Settings.Default.PathDirectory =
dialog.FileName;
Properties.Settings.Default.Save();
}
}
else
{
userAborted = true;
}
}
while (!pathOK && !userAborted);
return pathOK;
}
}
}

View file

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.1.243")] [assembly: AssemblyVersion("0.9.1.244")]
[assembly: AssemblyFileVersion("0.9.1.243")] [assembly: AssemblyFileVersion("0.9.1.244")]

View file

@ -70,5 +70,17 @@ namespace SystemTrayMenu.Properties {
this["HotKey"] = value; this["HotKey"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool IsUpgraded {
get {
return ((bool)(this["IsUpgraded"]));
}
set {
this["IsUpgraded"] = value;
}
}
} }
} }

View file

@ -14,5 +14,8 @@
<Setting Name="HotKey" Type="System.String" Scope="User"> <Setting Name="HotKey" Type="System.String" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>
<Setting Name="IsUpgraded" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View file

@ -211,6 +211,7 @@ namespace SystemTrayMenu
messageFilter.MouseLeave += fastLeave.Start; messageFilter.MouseLeave += fastLeave.Start;
fastLeave.Leave += FadeHalfOrOutIfNeeded; fastLeave.Leave += FadeHalfOrOutIfNeeded;
Config.UpgradeIfNotUpgraded();
if (!Config.LoadOrSetByUser()) if (!Config.LoadOrSetByUser())
{ {
cancelAppRun = true; cancelAppRun = true;

View file

@ -19,6 +19,9 @@
<setting name="HotKey" serializeAs="String"> <setting name="HotKey" serializeAs="String">
<value /> <value />
</setting> </setting>
<setting name="IsUpgraded" serializeAs="String">
<value>False</value>
</setting>
</SystemTrayMenu.Properties.Settings> </SystemTrayMenu.Properties.Settings>
</userSettings> </userSettings>
<!-- <!--