-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
109 lines (104 loc) · 4.33 KB
/
Program.cs
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
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCForge)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;
using System.Reflection;
namespace Starter
{
class Program
{
// Attempt to read the location from the DLL, if available.
public static string DLLLocation
{
get
{
return "http://www.mcforge.net/MCForge_.dll";
}
}
static int tries = 0;
static bool needsToRestart = false;
static string parent = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
//Console.ReadLine() is ignored while Starter is set as Windows Application in properties. (At least on Windows)
static void Main(string[] args)
{
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
try
{
if (File.Exists("Updater.exe"))
File.Delete("Updater.exe");
if (File.Exists("MCForge_.dll.backup"))
File.Delete("MCForge_.dll.backup");
}
catch { }
if (tries > 4)
{
Console.WriteLine("I'm afraid I can't download the file for some reason!");
Console.WriteLine("Go to " + DLLLocation + " yourself and download it, please");
Console.WriteLine("Place it inside my folder, near me, and restart me.");
Console.WriteLine("If you have any issues, get the files from the www.mcforge.net download page and try again.");
Console.WriteLine("Press any key to close me...");
MessageBox.Show("Unable to download MCForge_.dll. Please download it manually at " + DLLLocation + ", place it in the same folder as this executable, and restart this application", "Required DLL Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.ReadLine();
Console.WriteLine("Bye!");
}
else if (File.Exists("MCForge_.dll"))
{
//Crash issue fixed by re-executing the exe to properly load MCForge_.dll.
if (!needsToRestart)
openServer(args);
else
Process.Start(parent);
}
else
{
needsToRestart = true;
tries++;
Console.WriteLine("This is try number " + tries);
Console.WriteLine("You do not have the required DLL!");
Console.WriteLine("I'll download it for you. Just wait.");
Console.WriteLine("Downloading from " + DLLLocation);
try
{
WebClient Client = new WebClient();
Client.DownloadFile(DLLLocation, "MCForge_.dll");
Client.Dispose();
Console.WriteLine("Finished downloading! Let's try this again, shall we.");
for (int i = 0; i < 5; i++)
{
Thread.Sleep(100);
Console.Write(".");
}
Console.WriteLine("Go!");
Console.WriteLine();
Main(args);
}
catch
{
tries = 5;
Console.WriteLine("\nAn error occured while attempting to download MCForge_.dll\n");
Main(args);
}
}
}
static void openServer(string[] args)
{
MCForge_.Gui.Program.Main(args);
}
}
}