mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-05-16 02:13:39 +12:00
[Feature] if folder empty or not exists let user choose new root folder (#192), version 1.0.19.5
This commit is contained in:
parent
b5d35ea0d5
commit
8d5690928f
|
@ -79,6 +79,8 @@ namespace SystemTrayMenu.Business
|
|||
MessageBox.Show(Translator.GetText(
|
||||
"MessageRootFolderEmpty"));
|
||||
OpenFolder();
|
||||
Config.SetFolderByUser();
|
||||
openCloseState = OpenCloseState.Default;
|
||||
showingMessageBox = false;
|
||||
}
|
||||
|
||||
|
@ -88,8 +90,10 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
showingMessageBox = true;
|
||||
MessageBox.Show(Translator.GetText(
|
||||
"MessageRootFolderNoAccess"));
|
||||
"MessageRootFolderNoAccess"));
|
||||
OpenFolder();
|
||||
Config.SetFolderByUser();
|
||||
openCloseState = OpenCloseState.Default;
|
||||
showingMessageBox = false;
|
||||
}
|
||||
|
||||
|
@ -124,6 +128,12 @@ namespace SystemTrayMenu.Business
|
|||
{
|
||||
loadingRowData = rowData;
|
||||
|
||||
Menu menuLoading = menus[rowData.MenuLevel + 1];
|
||||
if (menuLoading != null && menuLoading.IsLoadingMenu)
|
||||
{
|
||||
CloseMenu(rowData.MenuLevel + 1);
|
||||
}
|
||||
|
||||
CreateAndShowLoadingMenu(rowData);
|
||||
void CreateAndShowLoadingMenu(RowData rowData)
|
||||
{
|
||||
|
@ -163,22 +173,15 @@ namespace SystemTrayMenu.Business
|
|||
void LoadSubMenuCompleted(object senderCompleted, RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
MenuData menuData = (MenuData)e.Result;
|
||||
if (menuData.Validity == MenuDataValidity.AbortedOrUnknown)
|
||||
|
||||
Menu menuLoading = menus[menuData.Level];
|
||||
if (menuLoading != null && menuLoading.IsLoadingMenu)
|
||||
{
|
||||
CloseLoadingMenu();
|
||||
void CloseLoadingMenu()
|
||||
{
|
||||
if (loadingRowData != null)
|
||||
{
|
||||
Menu menuLoading = menus[loadingRowData.MenuLevel + 1];
|
||||
if (menuLoading != null && menuLoading.IsLoadingMenu)
|
||||
{
|
||||
CloseMenu(loadingRowData.MenuLevel + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseMenu(menuData.Level);
|
||||
}
|
||||
else if (menus[0].IsUsable)
|
||||
|
||||
if (menuData.Validity != MenuDataValidity.AbortedOrUnknown &&
|
||||
menus[0].IsUsable)
|
||||
{
|
||||
Menu menu = Create(menuData);
|
||||
switch (menuData.Validity)
|
||||
|
|
|
@ -24,25 +24,23 @@ namespace SystemTrayMenu
|
|||
Translator.Initialize();
|
||||
Config.Initialize();
|
||||
Config.SetFolderByWindowsContextMenu(args);
|
||||
if (Config.LoadOrSetByUser())
|
||||
Config.LoadOrSetByUser();
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.ThreadException += ThreadException;
|
||||
static void ThreadException(object s, ThreadExceptionEventArgs t)
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.ThreadException += ThreadException;
|
||||
static void ThreadException(object s, ThreadExceptionEventArgs t)
|
||||
{
|
||||
AskUserSendError(t.Exception);
|
||||
}
|
||||
AskUserSendError(t.Exception);
|
||||
}
|
||||
|
||||
Scaling.Initialize();
|
||||
FolderOptions.Initialize();
|
||||
Scaling.Initialize();
|
||||
FolderOptions.Initialize();
|
||||
|
||||
using (new App())
|
||||
{
|
||||
isStartup = false;
|
||||
Log.WriteApplicationRuns();
|
||||
Application.Run();
|
||||
}
|
||||
using (new App())
|
||||
{
|
||||
isStartup = false;
|
||||
Log.WriteApplicationRuns();
|
||||
Application.Run();
|
||||
}
|
||||
|
||||
Config.Dispose();
|
||||
|
|
|
@ -57,11 +57,9 @@ namespace SystemTrayMenu
|
|||
}
|
||||
}
|
||||
|
||||
public static bool LoadOrSetByUser()
|
||||
public static void LoadOrSetByUser()
|
||||
{
|
||||
bool pathOK = IsPathOK(Path);
|
||||
|
||||
if (!pathOK)
|
||||
if (string.IsNullOrEmpty(Path))
|
||||
{
|
||||
string textFirstStart = Translator.GetText("TextFirstStart");
|
||||
MessageBox.Show(
|
||||
|
@ -69,64 +67,25 @@ namespace SystemTrayMenu
|
|||
Translator.GetText("SystemTrayMenu"),
|
||||
MessageBoxButtons.OK);
|
||||
ShowHelpFAQ();
|
||||
pathOK = SetFolderByUser();
|
||||
SetFolderByUser();
|
||||
}
|
||||
|
||||
return pathOK;
|
||||
}
|
||||
|
||||
public static bool SetFolderByUser(bool save = true)
|
||||
public static void 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 (dialog.ShowDialog() == DialogResult.OK)
|
||||
Settings.Default.PathDirectory = dialog.Folder;
|
||||
if (save)
|
||||
{
|
||||
if (IsPathOK(dialog.Folder))
|
||||
{
|
||||
pathOK = true;
|
||||
Settings.Default.PathDirectory =
|
||||
dialog.Folder;
|
||||
if (save)
|
||||
{
|
||||
Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
userAborted = true;
|
||||
Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
while (!pathOK && !userAborted);
|
||||
}
|
||||
|
||||
return pathOK;
|
||||
}
|
||||
|
||||
private static bool IsPathOK(string path)
|
||||
{
|
||||
bool isPathOK = false;
|
||||
|
||||
bool folderContainsFiles = false;
|
||||
try
|
||||
{
|
||||
folderContainsFiles = Directory.GetFiles(path).Length > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warn($"path:'{path}'", ex);
|
||||
}
|
||||
|
||||
isPathOK = FileLnk.IsNetworkPath(path) ||
|
||||
(Directory.Exists(path) && folderContainsFiles);
|
||||
|
||||
return isPathOK;
|
||||
}
|
||||
|
||||
internal static void ShowHelpFAQ()
|
||||
|
|
Loading…
Reference in a new issue