Skip to content

Commit

Permalink
Fixed crash when trying to set SteamCMD path.
Browse files Browse the repository at this point in the history
  • Loading branch information
Razzmatazzz committed Mar 1, 2021
1 parent 66bb286 commit 77e54d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
39 changes: 26 additions & 13 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,23 @@ public MainWindow()
servers = new List<ValheimServer>();
if (File.Exists(this.ServerJsonPath))
{
ValheimServer[] savedServers = JsonSerializer.Deserialize<ValheimServer[]>(File.ReadAllText(this.ServerJsonPath));
foreach (ValheimServer s in savedServers)
try
{
attachServerEventListeners(s);
servers.Add(s);
if (s.Autostart)
ValheimServer[] savedServers = JsonSerializer.Deserialize<ValheimServer[]>(File.ReadAllText(this.ServerJsonPath));
foreach (ValheimServer s in savedServers)
{
StartServer(s);
attachServerEventListeners(s);
servers.Add(s);
if (s.Autostart)
{
StartServer(s);
}
}
}
catch (Exception ex)
{
logMessage($"Error reading saved servers: {ex.Message}", LogEntryType.Error);
}
}
dgServers.ItemsSource = servers;
RefreshDataGrid();
Expand Down Expand Up @@ -263,12 +270,15 @@ private void CheckServerPath()
}
private void btnServerPath_Click(object sender, RoutedEventArgs e)
{
string filepath = txtServerPath.Text;
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.CheckFileExists = true;
if (File.Exists(filepath))
if (txtServerPath.Text.Length > 0)
{
openFileDialog.InitialDirectory = (new FileInfo(filepath)).DirectoryName;
string filepath = txtServerPath.Text;
openFileDialog.CheckFileExists = true;
if (File.Exists(filepath))
{
openFileDialog.InitialDirectory = (new FileInfo(filepath)).DirectoryName;
}
}
openFileDialog.Filter = "Server executable|valheim_server.exe";
openFileDialog.Title = "Select where valheim_server.exe is installed";
Expand Down Expand Up @@ -1119,11 +1129,14 @@ private void lblReportBug_MouseLeftButtonUp(object sender, MouseButtonEventArgs

private void btnSteamCmdPath_Click(object sender, RoutedEventArgs e)
{
var filepath = new FileInfo(txtSteamCmdPath.Text).Directory.FullName;
var openFolderDialog = new System.Windows.Forms.FolderBrowserDialog();
if (Directory.Exists(filepath))
if (txtSteamCmdPath.Text.Length > 0)
{
openFolderDialog.SelectedPath = filepath;
var filepath = new FileInfo(txtSteamCmdPath.Text).Directory.FullName;
if (Directory.Exists(filepath))
{
openFolderDialog.SelectedPath = filepath;
}
}
openFolderDialog.UseDescriptionForTitle = true;
openFolderDialog.Description = "Select SteamCMD installation folder";
Expand Down
6 changes: 3 additions & 3 deletions ValheimServerWarden.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<StartupObject>ValheimServerWarden.App</StartupObject>
<Version>0.4.1</Version>
<AssemblyVersion>0.4.1.0</AssemblyVersion>
<Version>0.4.2</Version>
<AssemblyVersion>0.4.2.0</AssemblyVersion>
<Product>Valheim Server Warden</Product>
<Authors>Razzmatazz</Authors>
<ApplicationIcon>Resources\vsw2.ico</ApplicationIcon>
<PackageId>ValheimServerWarden</PackageId>
<AssemblyName>Valheim Server Warden</AssemblyName>
<FileVersion>0.4.1.0</FileVersion>
<FileVersion>0.4.2.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down

0 comments on commit 77e54d5

Please sign in to comment.