Skip to content

Commit e537ec7

Browse files
committed
Show warning when HTML template file could not be loaded on startup.
fix #33
1 parent f2ff20a commit e537ec7

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

Sources/AppConfig.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//MIT License
22

3-
//Copyright (c) 2016-2024 Peter Kirmeier
3+
//Copyright (c) 2016-2025 Peter Kirmeier
44

55
//Permission is hereby granted, free of charge, to any person obtaining a copy
66
//of this software and associated documentation files (the "Software"), to deal
@@ -435,6 +435,8 @@ private void LoadSettings()
435435
if (_settings.Succession.SuccessionList.Count <= _settings.Succession.ActiveIndex) _settings.Succession.ActiveIndex = 0;
436436
profCtrl.InitializeProfilesControl(_settings.Profiles, _settings.Succession);
437437
profCtrl.om.Settings = _settings;
438+
if (!profCtrl.om.ReloadTemplate())
439+
MessageBox.Show("The file " + (string.IsNullOrEmpty(_settings.Inputfile) ? "<Inputfile not set>" : "\"" + _settings.Inputfile + "\"") + " not found!", "Error loading template!");
438440
profCtrl.om.Update(); // Write first output once after application start
439441

440442
// Configure hot keys..

Sources/OutModule.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//MIT License
22

3-
//Copyright (c) 2016-2024 Peter Kirmeier
3+
//Copyright (c) 2016-2025 Peter Kirmeier
44

55
//Permission is hereby granted, free of charge, to any person obtaining a copy
66
//of this software and associated documentation files (the "Software"), to deal
@@ -68,11 +68,7 @@ public OM_Severity Severity
6868
public SettingsRoot Settings
6969
{
7070
get { return _settings; }
71-
set
72-
{
73-
_settings = value;
74-
ReloadTemplate();
75-
}
71+
set { _settings = value; }
7672
}
7773

7874
#endregion
@@ -90,15 +86,16 @@ public OutModule(ProfilesControl ProfilesControl)
9086
/// Refreshes the file handles.
9187
/// Call when _settings.Inputfile changes!
9288
/// </summary>
93-
public void ReloadTemplate()
89+
public bool ReloadTemplate()
9490
{
9591
// Reload input file handle when possible
96-
if (File.Exists(_settings.Inputfile))
97-
{
98-
StreamReader sr = new (_settings.Inputfile);
99-
template = sr.ReadToEnd();
100-
sr.Close();
101-
}
92+
if (!File.Exists(_settings.Inputfile))
93+
return false;
94+
95+
StreamReader sr = new (_settings.Inputfile);
96+
template = sr.ReadToEnd();
97+
sr.Close();
98+
return true;
10299
}
103100

104101
#region JSON helpers
@@ -175,8 +172,7 @@ public void Update()
175172
if (null == _settings.OutputFile) return;
176173
if (null == template) // no valid template read yet?
177174
{
178-
ReloadTemplate(); // try to read template again
179-
if (null == template) return; // still invalid, avoid writing empty output file
175+
if (!ReloadTemplate()) return; // try to read template again. on error, avoid writing empty output file
180176
}
181177

182178
if (IsUpdateRunning) return; // Prevent multiple outputs at the same time (not thread safe, only works on same thread!)

0 commit comments

Comments
 (0)