-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpack_creator.nvgt
166 lines (166 loc) · 3.14 KB
/
pack_creator.nvgt
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
#include "bgt_compat.nvgt"
file f;
pack pfile;
bool encrypt;
string[] folder;
string encryption_key;
string filename;
string foldername;
string[] fol;
bool cont=true;
bool silent=false;
void main()
{
if (COMMAND_LINE=="/s")
silent=true;
if (file_exists("pack.pk"))
{
int a=0;
if (silent==false)
a=question("File was found.","Would you like to use the existing saved data?");
else
a=1;
if (a==1)
cont=false;
}
if (cont==false)
{
f.open("pack.pk","rb");
string a=f.read();
f.close();
string[] b=string_split(a,"{:}",true);
filename=b[0];
foldername=b[1];
int aencrypt=string_to_number(b[2]);
if (aencrypt==1)
encrypt=true;
else
encrypt=false;
if (encrypt==true)
encryption_key=b[3];
}
else if (cont==true)
{
filename=input_box("pack creator", "enter the name of the pack you wish to create");
if (filename=="")
{
exit();
}
foldername=input_box("pack creator", "enter the path that the files you wish to pack are contained.");
if (foldername=="")
{
exit();
}
int answer=question("pack creator", "would you like these files to be encrypted");
if (answer==1)
{
encrypt=true;
encryption_key=input_box("file encrypter", "enter the encryption key you wish to use.");
if (encryption_key=="")
{
exit();
}
}
else
{
encrypt=false;
}
string a="";
f.open("pack.pk","wb");
a=filename+"{:}"+foldername+"{:}";
if (encrypt==false)
a+="0";
else
a+="1{:}"+encryption_key;
f.write(a);
f.close();
}
if (silent==false)
show_game_window("creating pack file...");
if(!pfile.open(filename, PACK_OPEN_MODE_CREATE))
{
alert("error", "failed to create pack!");
exit();
}
if (!directory_exists(foldername))
{
if (silent==false)
alert("error", "folder does not exist!");
exit();
}
find_stuff(foldername);
if (silent==false)
alert("pack creator", "there are "+fol.length()+" files in the pack. Hit OK to start packing!");
for (uint i=0; i<fol.length(); i++)
{
if (silent==false)
show_game_window("packing file "+i+" of "+fol.length());
wait(5);
pfile.add_file(fol[i], string_replace(fol[i],foldername+"/","",true));
if(i%50==0)
wait(5);
}
if (silent==false)
alert("success!", "Files were added successfully!");
pfile.close();
exit();
}
void find_stuff(string path)
{
string[] items;
string[] folders=find_directories(path+"\\*");
items=folders;
string[] files=find_files(path+"\\*.*");
for(uint i=0; i<files.length(); i++)
{
fol.insert_last(path+"/"+files[i]);
}
if (items.length()>0)
{
for(uint i=0; i<items.length(); i++)
{
find_stuff(path+"/"+items[i]);
}
}
}
bool string_file_encrypt(string input_file, string output_file, string key)
{
bool success;
file f;
success=f.open(input_file, "rb");
if(!success) return false;
string text=f.read();
text=string_encrypt(text, key);
if(text=="") return false;
success=f.open(output_file, "wb");
if(!success) return false;
f.write(text);
success=f.close();
return success;
}
string script_get_path()
{
string scriptpath;
if(SCRIPT_COMPILED==false)
{
scriptpath=SCRIPT_CURRENT_FILE;
}
else
{
scriptpath=SCRIPT_EXECUTABLE;
}
return scriptpath;
}
string script_get_folder()
{
string path=script_get_path();
string[] spl=string_split(path, "\\", true);
spl.resize(spl.length()-1);
string folder;
for(uint i=0; i<spl.length(); i++)
{
folder+=spl[i];
if(i<spl.length()-1) folder+="\\";
}
return folder;
}