Skip to content

Commit

Permalink
More robust folder opening
Browse files Browse the repository at this point in the history
  • Loading branch information
Assistant committed Feb 27, 2020
1 parent b7eb585 commit 97d98b8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
20 changes: 20 additions & 0 deletions ModAssistant/Classes/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,26 @@ public static byte[] StreamToArray(Stream input)
}
}

public static void OpenFolder(string location)
{
if (!location.EndsWith(Path.DirectorySeparatorChar.ToString())) location += Path.DirectorySeparatorChar;
if (Directory.Exists(location))
{
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
{
FileName = location,
UseShellExecute = true,
Verb = "open"
});
return;
}
catch { }
}
MessageBox.Show($"{string.Format((string)Application.Current.FindResource("Utils:CannotOpenFolder"), location)}.");
}

public static async Task Download(string link, string output)
{
var resp = await HttpClient.GetAsync(link);
Expand Down
1 change: 1 addition & 0 deletions ModAssistant/Localisation/en-DEBUG.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@
<sys:String x:Key="Utils:NoInstallFolder">Utils:NoInstallFolder</sys:String>
<sys:String x:Key="Utils:RunAsAdmin">Utils:RunAsAdmin</sys:String>
<sys:String x:Key="Utils:InstallDir:DialogTitle">Utils:InstallDir:DialogTitle</sys:String>
<sys:String x:Key="Utils:CannotOpenFolder">Utils:CannotOpenFolder {0}</sys:String>
</ResourceDictionary>
1 change: 1 addition & 0 deletions ModAssistant/Localisation/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,5 @@
<sys:String x:Key="Utils:NoInstallFolder">Could not detect your Beat Saber install folder. Please select it manually.</sys:String>
<sys:String x:Key="Utils:RunAsAdmin">Mod Assistant needs to run this task as Admin. Please try again.</sys:String>
<sys:String x:Key="Utils:InstallDir:DialogTitle">Select your Beat Saber install folder</sys:String>
<sys:String x:Key="Utils:CannotOpenFolder">Can't open folder: {0}</sys:String>
</ResourceDictionary>
8 changes: 4 additions & 4 deletions ModAssistant/Pages/Options.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void SelectDirButton_Click(object sender, RoutedEventArgs e)

private void OpenDirButton_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start(InstallDirectory);
Utils.OpenFolder(InstallDirectory);
}

private void Test_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -162,7 +162,7 @@ private async void OpenLogsDirButton_Click(object sender, RoutedEventArgs e)
string title = (string)Application.Current.FindResource("Options:LogUploadFailed:Title");
string body = (string)Application.Current.FindResource("Options:LogUploadFailed:Body");
MessageBox.Show($"{body}\n ================= \n" + exception, title);
System.Diagnostics.Process.Start(Path.Combine(InstallDirectory, "Logs"));
Utils.OpenFolder(Path.Combine(InstallDirectory, "Logs"));
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ private void OpenAppDataButton_Click(object sender, RoutedEventArgs e)
string location = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
"AppData", "LocalLow", "Hyperbolic Magnetism");
System.Diagnostics.Process.Start(location);
Utils.OpenFolder(location);
}

private async void YeetBSIPAButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -272,7 +272,7 @@ private void ApplicationThemeOpenThemesFolder_Click(object sender, RoutedEventAr
{
if (Directory.Exists(Themes.ThemeDirectory))
{
System.Diagnostics.Process.Start(Themes.ThemeDirectory);
Utils.OpenFolder(Themes.ThemeDirectory);
}
else
{
Expand Down

0 comments on commit 97d98b8

Please sign in to comment.