This repository was archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (99 loc) · 3.51 KB
/
Copy pathProgram.cs
File metadata and controls
111 lines (99 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
namespace SPCodeUpdater
{
public static class Program
{
private static bool Success;
[STAThread]
public static void Main()
{
var processes = Process.GetProcessesByName("SPCode");
foreach (var process in processes)
{
try
{
process.WaitForExit();
}
catch (Exception)
{
}
}
Application.EnableVisualStyles();
Thread.Sleep(2000);
Application.SetCompatibleTextRenderingDefault(true);
var um = new UpdateMarquee();
um.Show();
Application.DoEvents(); //execute Visual
var t = new Thread(Worker);
t.Start(um);
Application.Run(um);
}
private static void Worker(object arg)
{
try
{
var um = (UpdateMarquee)arg;
#if BETA
var zipFile = ".\\SPCode.Beta.Portable.zip";
#else
var zipFile = ".\\SPCode.Portable.zip";
#endif
using (var fsInput = File.OpenRead(zipFile))
using (var zf = new ZipFile(fsInput))
{
foreach (ZipEntry zipEntry in zf)
{
if (zipEntry.Name.Contains("sourcepawn\\"))
{
continue;
}
var entryFileName = zipEntry.Name;
var fullZipToPath = Path.Combine(@".\", entryFileName);
var directoryName = Path.GetDirectoryName(fullZipToPath);
if (directoryName.Length > 0)
{
Directory.CreateDirectory(directoryName);
}
var buffer = new byte[4096];
using (var zipStream = zf.GetInputStream(zipEntry))
using (Stream fsOutput = File.Create(fullZipToPath))
{
StreamUtils.Copy(zipStream, fsOutput, buffer);
}
}
}
Success = true;
}
catch (Exception ex)
{
var sb = new StringBuilder();
sb.AppendLine("The updater failed to update SPCode properly.");
sb.AppendLine("=============================================");
sb.AppendLine($"Exception message: {ex.Message}");
sb.AppendLine("=============================================");
sb.AppendLine($"Stack trace:\n{ex.StackTrace}");
sb.AppendLine("=============================================");
var thread = new Thread(() => MessageBox.Show(sb.ToString()));
thread.Start();
Success = false;
}
finally
{
Process.Start(new ProcessStartInfo
{
Arguments = $"/C SPCode.exe {(Success ? "--updateok" : "--updatefail")}",
FileName = "cmd",
WindowStyle = ProcessWindowStyle.Hidden
});
Application.Exit();
}
}
}
}