forked from kettle-7/Kettle3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kettle3D-versions.py
214 lines (190 loc) · 6.67 KB
/
kettle3D-versions.py
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
versionlist = {
"dev" : [
[1, (20, 4, 'a')]
],
"stable" : [
#none yet...
]
}
# Updates need to be posted above with syntax as such:
# Developement versions go under "dev" and releases under "stable."
# dev[0][0] is the version number; 1 is the first version, 2 the second etc.
# The tuple contained within the array for the version is this:
# (<year released>, <month released>, <build name>). Please only add a single-letter build name corresponding to the order in which
# that month's versions were made.
# Feel free to make a pull request - put your version in the list. DO NOT MARK IT AS STABLE UNTIL I HAVE TESTED IT.
# Put the programming for the version in Kettle3D/versions/d20-04a.py. Add a txtfile object for all the text files, along with .py etc.
# Initialise the textfile under the play function. Make sure to add all required txtfiles and binaryfiles as well.
from tkinter import *
from urllib.request import urlopen
from os.path import normpath
from os import getenv
from os import getcwd
import time
import sys
import pickle
osnamefile = normpath(getcwd() + "/osname.txt")
osname = open(osnamefile).read()
if True:
#if osname == 'windows': # do windows-specific things
global directory
directory = getenv("%USERPROFILE%") + "\\AppData\\Roaming\\Kettle3D\\"
class file_dummy():
def open(self, a=None, b=None, c=None):
pass
def close(self):
pass
def read(self):
pass
def write(self):
pass
try:
filelistfile = open(directory + normpath("assets/files.dat"), 'rb')
files = pickle.load(filelistfile)
print("Successfully retrieved file array.")
filelistfile.close()
except (FileNotFoundError, OSError):
filelistfile = open(directory + normpath("assets/files.dat"), 'xb')
files = {# This is the filearray. It stores all the information needed to find other files, whether binary or normal text.
"binary" : [
{# This is a file entry as provided by the downloadfile class. This entry belongs to the file array itself.
"path" : "assets/files.dat",
"version" : 1
}
],
"txt" : [
]
}
pickle.dump(files, filelistfile)
print("Successfully created a new filearray.")
filelistfile.close()
class txtfile():
def __init__(self, path, version, newcontent=None): # file for download
self.path = path
self.version = version
self.winpath = normpath(self.path)
self.newcontent = newcontent
print("Looking for file %s..." % path)
try:
self.newcontent = open(directory + winpath, 'w')
self.oldcontent = open(directory + winpath, 'r')
print("File %s found successfully." % path)
try:
self.onlinecontent = urlopen("https://raw.githubusercontent.com/Kettle3D/Kettle3D/master/" + path).read().decode('utf-8')
if self.oldcontent != self.onlinecontent:
self.newcontent.write(self.onlinecontent)
print("Successfully updated file.")
else:
print("File matches.")
except:
print("Couldn't update file. Maybe try checking your internet connection?")
except (FileNotFoundError, OSError):
self.newcontent = open(directory + winpath, 'x')
print("File %s created successfully." % path)
try:
self.onlinecontent = urlopen("https://raw.githubusercontent.com/Kettle3D/Kettle3D/master/" + path).read().decode('utf-8')
print("Successfully downloaded file.")
fae = {
"path" : self.path,
"winpath" : self.winpath,
"version" : self.version
}
files[txt].append(fae)
except:
print("Couldn't download file. Maybe try checking your internet connection?")
finally:
self.newcontent.close()
class binaryfile():
def __init__(self, path, version): # file for download
self.path = path
self.version = version
self.winpath = normpath(self.path)
print("Looking for file %s..." % path)
try:
self.newcontent = open(directory + winpath, 'wb')
self.oldcontent = open(directory + winpath, 'rb')
print("File %s found successfully." % path)
try:
self.onlinecontent = urlopen("https://raw.githubusercontent.com/Kettle3D/Kettle3D/master/" + path, 'rb').read().decode('utf-8')
if self.oldcontent != self.onlinecontent:
self.newcontent.write(self.onlinecontent)
print("Successfully updated file.")
else:
print("File matches.")
except:
print("Couldn't update file. Maybe try checking your internet connection?")
except (FileNotFoundError, OSError):
self.content = open(directory + winpath, 'xb')
print("File %s created successfully." % path)
try:
self.onlinecontent = urlopen("https://raw.githubusercontent.com/Kettle3D/Kettle3D/master/" + path, 'rb').read().decode('utf-8')
print("Successfully downloaded file.")
fae = {
"path" : self.path,
"winpath" : self.winpath,
"version" : self.version
}
files[txt].append(fae)
except:
print("Couldn't download file. Maybe try checking your internet connection?")
finally:
self.content.close()
isdiropen = False
isplayopen = False
dir_tk = None
play_tk = None
tk = Tk()
tk.title("Kettle3D Launcher")
tk.wm_attributes("-topmost", 1)
canvas = Canvas(tk, width=500, height=500, bd=0, highlightthickness=0)
canvas.pack()
tk.update()
print("The launcher window opened successfully.")
print("Have 1 files to update or download.")
thomas = file_dummy()
assets_index = txtfile("assets/assets_index.py", "assets\index\\assets_index.py", 1, thomas)
print("Finished checking files.")
def play():
isplayopen = True
play_tk = Tk()
play_tk.title("Versions - Kettle3D Launcher")
play_tk.wm_attributes("-topmost", 1)
play_canvas = Canvas(play_tk, width=250, height=250)
play_canvas.pack()
play_tk.update()
tk.update()
def closedirwin():
if isdiropen:
dir_tk.destroy()
dir_tk = None
isdiropen = False
def launch():
play_tk.destroy()
isplayopen = False
def dir():
# Change directory
isdiropen = True
dir_tk = Tk()
dir_tk.title("Change Directory - Kettle3D Launcher")
dir_tk.wm_attributes("-topmost", 1)
dir_canvas = Canvas(dir_tk, width=500, height=20)
dir_canvas.pack()
dir_tk.update()
tk.update()
dirtxt = dir_canvas.create_text(250, 11, text="The directory is set to %s." % directory, font=('Helvetica', 15))
choosedir = Button(tk, text="Change Directory", command=dir)
playbtn = Button(tk, text="PLAY", command=play)
choosedir.pack()
playbtn.pack()
closebtn = Button(tk, text="Cancel", command=closedirwin)
while True:
tk.update_idletasks()
tk.update()
if isdiropen:
dir_canvas.itemconfig(dirtxt, x=dir_tk.winfo_width(), text="The directory is set to %s." % directory)
dir_tk.update_idletasks()
dir_tk.update()
if isplayopen:
play_tk.update_idletasks()
play_tk.update()
time.sleep(0.01)