Skip to content

Commit 87e33cd

Browse files
Addin' everything, hopefully
1 parent 8cd17aa commit 87e33cd

132 files changed

Lines changed: 25126 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

StoDemoLauncher.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30503.244
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StoDemoLauncher", "StoDemoLauncher\StoDemoLauncher.csproj", "{43F03D56-50FE-48DD-8ED5-B8249BC758DB}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{43F03D56-50FE-48DD-8ED5-B8249BC758DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{43F03D56-50FE-48DD-8ED5-B8249BC758DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{43F03D56-50FE-48DD-8ED5-B8249BC758DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{43F03D56-50FE-48DD-8ED5-B8249BC758DB}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {68A3A54D-AE55-4732-858D-E5E296E54738}
24+
EndGlobalSection
25+
EndGlobal

StoDemoLauncher/BackupManager.cs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Windows.Forms;
6+
using StoDemoLauncher.Model;
7+
8+
namespace StoDemoLauncher
9+
{
10+
/// <summary>
11+
/// Creates, reads, and restores demo backups
12+
/// </summary>
13+
public class BackupManager
14+
{
15+
private GameClient gameClient;
16+
17+
public BackupManager(GameClient gameClient)
18+
{
19+
this.gameClient = gameClient;
20+
}
21+
22+
/// <summary>
23+
/// Backs up a demo file
24+
/// </summary>
25+
/// <param name="demo">DemoFileInfo of the demo to backup</param>
26+
/// <returns>true if the backup was written, false otherwise</returns>
27+
public bool BackupDemo(DemoInfo demo)
28+
{
29+
// backup file by default
30+
DialogResult overwriteConfirmed = DialogResult.Yes;
31+
32+
if (System.IO.File.Exists(this.GetDemoBackupPath(demo)))
33+
{
34+
overwriteConfirmed = MessageBox.Show(
35+
"There already exists a backup of this demo file. You can\n" +
36+
"replace the existing backup with the current version of\n" +
37+
"this demo file. Make sure, the current version is working\n" +
38+
"properly and is not corrupted. This action cannot be\n" +
39+
"undone.\n\n" +
40+
"Do you want to replace the existing backup?",
41+
"Confirm File Replace",
42+
MessageBoxButtons.YesNo,
43+
MessageBoxIcon.Warning,
44+
MessageBoxDefaultButton.Button2);
45+
}
46+
if (overwriteConfirmed.Equals(DialogResult.Yes))
47+
{
48+
if (!System.IO.Directory.Exists(this.GetDemosBackupPath(demo.Server))) System.IO.Directory.CreateDirectory(this.GetDemosBackupPath(demo.Server));
49+
System.IO.File.Copy(this.gameClient.GetDemoPath(demo), this.GetDemoBackupPath(demo), true);
50+
return true;
51+
}
52+
else
53+
{
54+
return false;
55+
}
56+
}
57+
58+
/// <summary>
59+
/// Restores demo from a backup
60+
/// </summary>
61+
/// <param name="demo"></param>
62+
/// <returns>true if the demo was replaced with the backup, false
63+
/// otherwise</returns>
64+
public bool RestoreBackup(DemoInfo demo)
65+
{
66+
// restore file by default
67+
DialogResult overwriteConfirmed = DialogResult.Yes;
68+
69+
if (System.IO.File.Exists(this.GetDemoBackupPath(demo)))
70+
{
71+
overwriteConfirmed = MessageBox.Show(
72+
"You are about to replace this demo file with a backup.\n" +
73+
"This action cannot be undone.\n\n" +
74+
"Do you want to replace the existing file with the backup?",
75+
"Confirm File Replace",
76+
MessageBoxButtons.YesNo,
77+
MessageBoxIcon.Warning,
78+
MessageBoxDefaultButton.Button2);
79+
}
80+
if (overwriteConfirmed.Equals(DialogResult.Yes))
81+
{
82+
System.IO.File.Copy(this.GetDemoBackupPath(demo), this.gameClient.GetDemoPath(demo), true);
83+
return true;
84+
}
85+
else
86+
{
87+
return false;
88+
}
89+
}
90+
91+
/// <summary>
92+
/// Returns the path to the demos backup folder
93+
/// </summary>
94+
/// <param name="server">The installation for which to backup</param>
95+
/// <returns>The path to the demos backup folder</returns>
96+
public string GetDemosBackupPath(GameServer server)
97+
{
98+
return this.gameClient.GetDemosPath(server) + "\\StoDemoLauncherBackup";
99+
}
100+
101+
/// <summary>
102+
/// Returns the filename for the backup of a demo file
103+
/// </summary>
104+
/// <param name="demo">DemoFileInfo of the demo to backup</param>
105+
/// <returns>The absolute path the demo backup</returns>
106+
public string GetDemoBackupPath(DemoInfo demo)
107+
{
108+
return this.GetDemosBackupPath(demo.Server) + "\\" + demo.FileName;
109+
}
110+
111+
/// <summary>
112+
/// Chekcs if a given demo file has a backup
113+
/// </summary>
114+
/// <param name="demo">DemoFileInfo for the demo to check</param>
115+
/// <returns>true if the demo file has a backup, false otherwise</returns>
116+
public bool hasBackup(DemoInfo demo)
117+
{
118+
return System.IO.File.Exists(this.GetDemoBackupPath(demo));
119+
}
120+
}
121+
}

StoDemoLauncher/BusyForm.Designer.cs

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

StoDemoLauncher/BusyForm.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Windows.Forms;
9+
using System.Threading;
10+
11+
namespace StoDemoLauncher
12+
{
13+
public partial class BusyForm : Form
14+
{
15+
/// <summary>
16+
/// Singleton instance
17+
/// </summary>
18+
private static BusyForm instance = null;
19+
20+
private static Point location = new Point(100, 100);
21+
22+
/// <summary>
23+
/// The threat for this form
24+
/// </summary>
25+
private static Thread thread = null;
26+
27+
/// <summary>
28+
/// Private constructor for singleton pattern
29+
/// </summary>
30+
private BusyForm()
31+
{
32+
InitializeComponent();
33+
//this.progressBar.MarqueeAnimationSpeed = 30;
34+
}
35+
36+
/// <summary>
37+
/// Launches SplashScreen
38+
/// </summary>
39+
static private void ShowForm()
40+
{
41+
instance = new BusyForm();
42+
instance.Location = BusyForm.location;
43+
instance.ShowDialog();
44+
}
45+
46+
/// <summary>
47+
/// Closes the SplashScreen
48+
/// </summary>
49+
static private void CloseForm()
50+
{
51+
instance.Close();
52+
instance = null;
53+
}
54+
55+
/// <summary>
56+
/// makes the Splash screen visible
57+
/// </summary>
58+
static public void ShowBusyScreen(Form owner)
59+
{
60+
// Make sure it is only launched once.
61+
if (instance != null)
62+
return;
63+
BusyForm.location = owner.Location;
64+
BusyForm.location.X += owner.Size.Width / 2 - 100;
65+
BusyForm.location.Y += owner.Size.Height / 2 - 35;
66+
thread = new Thread(new ThreadStart(BusyForm.ShowForm));
67+
thread.IsBackground = true;
68+
thread.SetApartmentState(ApartmentState.STA);
69+
thread.Start();
70+
}
71+
72+
/// <summary>
73+
/// makes the Spash screen disappear
74+
/// </summary>
75+
static public void HideBusyScreen()
76+
{
77+
if (instance != null)
78+
{
79+
// There might occur a racing condition, when we rapidly open and close a form.
80+
// So we may need to wait for the form to initialize and cloase it then again
81+
bool closed = false;
82+
while (!closed)
83+
{
84+
try
85+
{
86+
instance.Invoke(new MethodInvoker(delegate { CloseForm(); }));
87+
closed = true;
88+
}
89+
catch
90+
{
91+
System.Threading.Thread.Sleep(100);
92+
}
93+
}
94+
}
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)