-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.pas
161 lines (139 loc) · 3.88 KB
/
main.pas
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
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
ComCtrls, utils, fpjson, jsonparser, fileutil, md5, windows;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
EditModsPath: TEdit;
EditModsURL: TEdit;
Label1: TLabel;
Label2: TLabel;
Logger: TMemo;
ProgressBar1: TProgressBar;
SelectDirectoryDialog1: TSelectDirectoryDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure EditModsPathChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
version: string;
implementation
{$R *.lfm}
{ TForm1 }
var
requests: TRequests;
md5obj: TJSONObject;
procedure TForm1.FormCreate(Sender: TObject);
var
config: TJSONObject;
begin
Form1.Caption := Form1.Caption;
requests.get('https://raw.githubusercontent.com/Augmeneco/AugModsChecker/master/version');
if requests.text <> version then
begin
ShowMessage(Format('Your version of AMC (%s) is outdated%sThe latest version is %s',
[version,LineEnding,requests.text]));
ShellExecute(0, nil,'https://augmeneco.github.io/AugModsChecker/',nil,nil,1);
Halt;
end;
if FileExists('config.json') then
begin
config := TJSONObject(GetJSON(utils.readfile('config.json')));
EditModsPath.Text := config['modspath'].AsString;
EditModsURL.Text := config['modsurl'].AsString;
logWrite('Loaded config.json');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if SelectDirectoryDialog1.Execute then
begin
EditModsPath.Text := SelectDirectoryDialog1.FileName;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
git: TGit;
begin
if not DirectoryExists(EditModsPath.text) then
begin
ShowMessage('There is no such folder');
exit;
end;
if EditModsURL.text = '' then
begin
ShowMessage('You must enter the server link');
exit;
end;
git := TGit.Create(EditModsURL.text);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
config: TJSONObject;
begin
config := TJSONObject.Create;
config.Add('modspath',EditModsPath.Text);
config.Add('modsurl',EditModsURL.Text);
utils.writefile('config.json',config.FormatJSON());
logwrite('Saved config.json');
end;
procedure GenMD5(path: string);
var
f_list: TStringList;
md5, filename: string;
farray: TStringArray;
i: integer;
begin
f_list := FindAllFiles(path,'*', true );
logwrite('[ Creating md5list.json ]'+LineEnding+'Found '+inttostr(f_list.count)+' files:');
md5obj.add('augmc_version',version);
for i:=0 to f_list.Count-1 do
begin
filename := f_list[i];
farray := filename.split('\');
filename := farray[Length(farray)-1];
md5 := MD5Print(MD5File(f_list[i]));
md5obj.Add(filename,md5);
Form1.Logger.Lines.Add(#9+filename);
end;
utils.writefile('md5list.json',md5obj.FormatJSON());
logwrite('Saved md5list.json');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
GenMD5(EditModsPath.text);
end;
procedure TForm1.EditModsPathChange(Sender: TObject);
var
AppDataDir: string;
begin
if veryBadToLower(EditModsPath.Text) = 'minecraft' then
begin
AppDataDir := SysUtils.GetEnvironmentVariable('appdata');
if DirectoryExists(AppDataDir+'\.minecraft') = True then
EditModsPath.Text := AppDataDir+'\.minecraft\mods'
else
begin
ShowMessage('You don''t have Minecraft installed!');
EditModsPath.Text := '';
end;
end;
end;
begin
requests := TRequests.Create;
md5obj := TJSONObject.Create;
version := '1.1.3';
end.