forked from neophoenix236/INVedit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (65 loc) · 1.94 KB
/
Program.cs
File metadata and controls
71 lines (65 loc) · 1.94 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
using System;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Reflection;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace INVedit
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
List<string> files = new List<string>();
foreach (string arg in args)
if (arg.Length > 0 && arg[0] == '-') {
switch (args[0]) {
case "-update":
if (File.Exists("NBT.dll"))
RepeatUntilSuccessful(() => File.Delete("NBT.dll"));
if (File.Exists("_INVedit.exe")) {
RepeatUntilSuccessful(() => File.Delete("INVedit.exe"));
File.Copy("_INVedit.exe", "INVedit.exe");
Process.Start("INVedit.exe", "-finish");
return;
}
break;
case "-finish":
RepeatUntilSuccessful(() => File.Delete("_INVedit.exe"));
break;
}
} else { files.Add(arg); }
if (!File.Exists("items.txt")) {
MessageBox.Show("Couldn't find file 'items.txt'.\n" +
"Did you unpack INVedit correctly?", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(files.ToArray()));
}
private static void RepeatUntilSuccessful(Action action)
{
int times = 0;
while (true) {
try { action(); break; } catch { }
Thread.Sleep(500);
if (times++ > 4) {
var result = MessageBox.Show("Couldn't update INVedit.\n" +
"Is another instance of INVedit running?", "Warning",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
if (result == DialogResult.Cancel)
Application.Exit();
times = 0;
}
}
}
}
}