This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
191 lines (183 loc) · 8 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using Salaros.Configuration;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace MythicalLauncher
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
public static string version = "1.0.7";
public static string debugmode;
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Contains("-version"))
{
AttachConsole(ATTACH_PARENT_PROCESS);
Console.Title = "MythicalLauncher | CLI";
Console.WriteLine("@echo off");
Console.Clear();
Console.WriteLine("MythicalLauncher version " + version + " by MythicalSystems");
Console.WriteLine("");
return;
}
if (args.Contains("-debug"))
{
AttachConsole(ATTACH_PARENT_PROCESS);
Console.Title = "MythicalLauncher | CLI";
Console.WriteLine("@echo off");
Console.Clear();
Console.WriteLine("MythicalLauncher version " + version + " by MythicalSystems");
Console.WriteLine("");
Console.WriteLine("DEBUG MODE ACTIVE");
Console.WriteLine("Please do not use this mode if you are not a developer");
debugmode = "true";
try
{
Application.Run(new FrmLoading());
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Console.WriteLine("An error occurred: " + ex.Message);
}
return;
}
if (args.Contains("-update"))
{
AttachConsole(ATTACH_PARENT_PROCESS);
Console.Title = "MythicalLauncher | CLI";
Console.WriteLine("@echo off");
Console.Clear();
Console.WriteLine("MythicalLauncher version " + version + " by MythicalSystems");
Console.WriteLine("");
askUpdate();
Boolean checkUpdate()
{
Console.WriteLine("[{0:HH:mm:ss}] [UPDATER] Please wait while we check for updates", DateTime.Now);
Boolean versionStatu;
try
{
WebClient client = new WebClient();
var appcfg = new ConfigParser(Application.StartupPath + @"\settings.ini");
var r_key = appcfg.GetValue("RemoteLauncher", "key");
Stream str = client.OpenRead(r_key + "/api/mythicallauncher/settings/update.php?version=" + Program.version);
StreamReader reader = new StreamReader(str);
String content = reader.ReadToEnd();
versionStatu = (content == "GETUPDATE") ? versionStatu = true : versionStatu = false;
}
catch { versionStatu = false; }
return versionStatu;
}
void askUpdate()
{
if (checkUpdate())
{
Console.WriteLine("[{0:HH:mm:ss}] [UPDATER] Update found!", DateTime.Now);
DialogResult dr = MessageBox.Show("New update is available. \n\r Would you like to install it now?", "Update found", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
getUpdate();
}
if (dr == DialogResult.No)
{
Application.Exit();
}
}
else
{
Console.WriteLine("[{0:HH:mm:ss}] [UPDATER] No updates found", DateTime.Now);
}
}
void getUpdate()
{
Application.Run(new FrmUpdate());
}
Console.WriteLine("Press any key to continue!");
return;
}
if (args.Contains("-fix-missing"))
{
AttachConsole(ATTACH_PARENT_PROCESS);
Console.Title = "MythicalLauncher | CLI";
Console.WriteLine("@echo off");
Console.Clear();
Console.WriteLine("Welcome to MythicalLauncher version " + version);
Console.WriteLine("");
if (File.Exists("version"))
{
Console.WriteLine("[{0:HH:mm:ss}] [REGEN] Nothing to do file called 'verion' exist", DateTime.Now);
}
else
{
try
{
using (StreamWriter sw = File.CreateText("version"))
{
sw.WriteLine(version);
Console.WriteLine("[{0:HH:mm:ss}] [REGEN] We created the file called 'version'!", DateTime.Now);
}
}
catch (Exception ex)
{
Console.WriteLine("[{0:HH:mm:ss}] [REGEN] " + ex.Message, DateTime.Now);
}
}
if (File.Exists("buildnumber"))
{
Console.WriteLine("[{0:HH:mm:ss}] [REGEN] Nothing to do file called 'buildnumber' exist", DateTime.Now);
}
else
{
try
{
using (StreamWriter sw = File.CreateText("buildnumber"))
{
sw.WriteLine("Unknown");
Console.WriteLine("[{0:HH:mm:ss}] [REGEN] We created the file called 'buildnumber'!", DateTime.Now);
}
}
catch (Exception ex)
{
Console.WriteLine("[{0:HH:mm:ss}] [REGEN] " + ex.Message, DateTime.Now);
}
}
Console.WriteLine("Press any key to continue!");
return;
}
if (args.Contains("-help"))
{
AttachConsole(ATTACH_PARENT_PROCESS);
Console.Title = "MythicalLauncher | CLI";
Console.WriteLine("@echo off");
Console.Clear();
Console.WriteLine("Welcome to MythicalLauncher version " + version);
Console.WriteLine("");
Console.WriteLine("Thanks for using MythicalLauncher CLI here are the commands that may help you");
Console.WriteLine("");
Console.WriteLine("-help | Shows this promot");
Console.WriteLine("-version | Shows the version of the application");
Console.WriteLine("-debug | Shows the debug console for problems");
Console.WriteLine("-fix-missing | This is a fix if the files are missing");
Console.WriteLine("-update | This updates to the last version from github");
Console.WriteLine("");
Console.WriteLine("Press any key to continue!");
return;
}
debugmode = "true";
Application.Run(new FrmLoading());
}
}
}