Skip to content

Commit d0b9972

Browse files
committed
Additional fixes for startup crashes.
1 parent 312680d commit d0b9972

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</TabItem>
8383
<TabItem x:Name="tabLog" Header="Log">
8484
<Grid>
85-
<TextBox x:Name="txtLog" TextWrapping="Wrap" Background="White" VerticalScrollBarVisibility="Auto" Grid.ColumnSpan="2"/>
85+
<RichTextBox x:Name="txtLog" Background="#FF4B4B4B" VerticalScrollBarVisibility="Auto" Grid.ColumnSpan="2" Foreground="White"/>
8686
</Grid>
8787
</TabItem>
8888
</TabControl>

MainWindow.xaml.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public partial class MainWindow : Window
3838
private static string saveDirPath;
3939
private List<SaveBackup> listBackups;
4040
private Boolean suppressLog;
41+
private Color defaultTextColor;
4142
private FileSystemWatcher worldWatcher;
4243
private FileSystemWatcher charWatcher;
4344

@@ -120,11 +121,15 @@ public MainWindow()
120121
{
121122
InitializeComponent();
122123
suppressLog = false;
123-
txtLog.Text = "Version " + typeof(MainWindow).Assembly.GetName().Version;
124124
if (Properties.Settings.Default.CreateLogFile)
125125
{
126-
System.IO.File.WriteAllText("log.txt", DateTime.Now.ToString() + ": Version " + typeof(MainWindow).Assembly.GetName().Version + "\r\n");
126+
System.IO.File.WriteAllText("log.txt", "");
127127
}
128+
defaultTextColor = ((SolidColorBrush)txtLog.Foreground).Color;
129+
Debug.WriteLine(defaultTextColor);
130+
txtLog.IsReadOnly = true;
131+
txtLog.Document.Blocks.Clear();
132+
logMessage($"Version {typeof(MainWindow).Assembly.GetName().Version}");
128133
logMessage("Loading...");
129134
if (Properties.Settings.Default.UpgradeRequired)
130135
{
@@ -195,7 +200,8 @@ public MainWindow()
195200
}
196201
else
197202
{
198-
logMessage($@"Folder {saveDirPath}\characters does not exist. Please set the correct location of your save files.", LogType.Error);
203+
Directory.CreateDirectory($@"{ saveDirPath}\characters");
204+
//logMessage($@"Folder {saveDirPath}\characters does not exist. Please set the correct location of your save files.", LogType.Error);
199205
}
200206

201207
// Watch for changes in LastWrite times.
@@ -338,19 +344,20 @@ private void loadBackups(Boolean verbose)
338344

339345
public void logMessage(string msg)
340346
{
341-
logMessage(msg, Colors.White);
347+
logMessage(msg, defaultTextColor);
342348
}
343349

344350
public void logMessage(string msg, LogType lt)
345351
{
346-
Color color = Colors.White;
352+
//Color color = Colors.White;
353+
Color color = defaultTextColor;
347354
if (lt == LogType.Success)
348355
{
349-
color = Color.FromRgb(0, 200, 0);
356+
color = Color.FromRgb(50, 200, 50);
350357
}
351358
else if (lt == LogType.Error)
352359
{
353-
color = Color.FromRgb(200, 0, 0);
360+
color = Color.FromRgb(200, 50, 50);
354361
}
355362
logMessage(msg, color);
356363
}
@@ -359,10 +366,15 @@ public void logMessage(string msg, Color color)
359366
{
360367
if (!suppressLog)
361368
{
362-
txtLog.Text = txtLog.Text + Environment.NewLine + DateTime.Now.ToString() + ": " + msg;
369+
//txtLog.Text = txtLog.Text + Environment.NewLine + DateTime.Now.ToString() + ": " + msg;
370+
Run run = new Run(DateTime.Now.ToString() + ": " + msg);
371+
run.Foreground = new SolidColorBrush(color);
372+
Paragraph paragraph = new Paragraph(run);
373+
paragraph.Margin = new Thickness(0);
374+
txtLog.Document.Blocks.Add(paragraph);
363375
lblLastMessage.Content = msg;
364376
lblLastMessage.Foreground = new SolidColorBrush(color);
365-
if (color.Equals(Colors.White))
377+
if (color.Equals(defaultTextColor))
366378
{
367379
lblLastMessage.FontWeight = FontWeights.Normal;
368380
}
@@ -386,6 +398,10 @@ private void BtnBackup_Click(object sender, RoutedEventArgs e)
386398
{
387399
doBackup(save);
388400
}
401+
if (!Directory.Exists($@"{saveDirPath}\characters"))
402+
{
403+
Directory.CreateDirectory($@"{saveDirPath}\characters");
404+
}
389405
string[] characters = Directory.GetFiles($@"{saveDirPath}\characters", "*.fch");
390406
foreach (string save in characters)
391407
{
@@ -1103,12 +1119,16 @@ private void btnSaveFolder_Click(object sender, RoutedEventArgs e)
11031119
{
11041120
return;
11051121
}
1106-
if (!Directory.Exists($@"{folderName}\worlds") || !Directory.Exists($@"{folderName}\characters"))
1122+
if (!Directory.Exists($@"{folderName}\worlds"))
11071123
{
11081124
MessageBox.Show("Please select the folder where your Valheim save files are located. This folder should contain both a \"worlds\" and a \"characters\" folder..",
11091125
"Invalid Folder", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
11101126
return;
11111127
}
1128+
if (!Directory.Exists($@"{folderName}\characters"))
1129+
{
1130+
Directory.CreateDirectory($@"{folderName}\characters");
1131+
}
11121132
txtSaveFolder.Text = folderName;
11131133
saveDirPath = folderName;
11141134
worldWatcher.Path = $@"{saveDirPath}\worlds";

Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// General Information about an assembly is controlled through the following
88
// set of attributes. Change these attribute values to modify the information
99
// associated with an assembly.
10-
[assembly: AssemblyTitle("ValheimSaveShield")]
10+
[assembly: AssemblyTitle("Valheim Save Shield")]
1111
[assembly: AssemblyDescription("")]
1212
[assembly: AssemblyConfiguration("")]
1313
[assembly: AssemblyCompany("")]
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("0.1.2.0")]
55-
[assembly: AssemblyFileVersion("0.1.2.0")]
54+
[assembly: AssemblyVersion("0.1.3.0")]
55+
[assembly: AssemblyFileVersion("0.1.3.0")]

0 commit comments

Comments
 (0)