forked from Podshot/MCEdit-Unified
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcedit.py
830 lines (702 loc) · 27.6 KB
/
mcedit.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
# !/usr/bin/env python2.7
# -*- coding: utf_8 -*-
# import resource_packs # not the right place, moving it a bit further
#-# Modified by D.C.-G. for translation purpose
#.# Marks the layout modifications. -- D.C.-G.
"""
mcedit.py
Startup, main menu, keyboard configuration, automatic updating.
"""
import splash
import resource_packs
import version_utils
import OpenGL
import sys
import os
import directories
import keys
if "-debug" not in sys.argv:
OpenGL.ERROR_CHECKING = False
import logging
# Setup file and stderr logging.
logger = logging.getLogger()
# Set the log level up while importing OpenGL.GL to hide some obnoxious warnings about old array handlers
logger.setLevel(logging.WARN)
from OpenGL import GL
logger.setLevel(logging.DEBUG)
logfile = 'mcedit.log'
# if hasattr(sys, 'frozen'):
# if sys.platform == "win32":
# import esky
# app = esky.Esky(sys.executable)
# logfile = os.path.join(app.appdir, logfile)
#
if sys.platform == "darwin":
logfile = os.path.expanduser("~/Library/Logs/mcedit.log")
fh = logging.FileHandler(logfile, mode="w")
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.WARN)
if "-v" in sys.argv:
ch.setLevel(logging.INFO)
if "-vv" in sys.argv:
ch.setLevel(logging.DEBUG)
class FileLineFormatter(logging.Formatter):
def format(self, record):
record.__dict__['fileline'] = "%(module)s.py:%(lineno)d" % record.__dict__
record.__dict__['nameline'] = "%(name)s.py:%(lineno)d" % record.__dict__
return super(FileLineFormatter, self).format(record)
fmt = FileLineFormatter(
'[%(levelname)8s][%(nameline)30s]:%(message)s'
)
fh.setFormatter(fmt)
ch.setFormatter(fmt)
logger.addHandler(fh)
logger.addHandler(ch)
import albow
import locale
DEF_ENC = locale.getdefaultlocale()[1]
if DEF_ENC is None:
DEF_ENC = "UTF-8"
from albow.translate import _, getPlatInfo
from albow.dialogs import Dialog
from albow.openglwidgets import GLViewport
from albow.root import RootWidget
from config import config
albow.resource.resource_dir = directories.getDataDir()
import panels
import functools
import glutils
import leveleditor
# Building translation template
if "-tt" in sys.argv:
albow.translate.buildTemplate = True
albow.translate.loadTemplate()
import mceutils
import mcplatform
#-# DEBUG
if mcplatform.hasXlibDisplay:
print '*** Xlib version', str(mcplatform.Xlib.__version__).replace(' ', '').replace(',', '.')[1:-1], 'found in',
if os.path.expanduser('~/.local/lib/python2.7/site-packages') in mcplatform.Xlib.__file__:
print 'user\'s',
else:
print 'system\'s',
print 'libraries.'
#-#
from mcplatform import platform_open
import numpy
from pymclevel.minecraft_server import ServerJarStorage
import os
import os.path
import pygame
from pygame import display, rect
import pymclevel
import release
import shutil
import sys
import traceback
import threading
from utilities.gl_display_context import GLDisplayContext
#&# Prototype fro blocks/items names
import mclangres
#&#
getPlatInfo(OpenGL=OpenGL, numpy=numpy, pygame=pygame)
ESCAPE = '\033'
class MCEdit(GLViewport):
#debug_resize = True
def __init__(self, displayContext, *args):
ws = displayContext.getWindowSize()
r = rect.Rect(0, 0, ws[0], ws[1])
GLViewport.__init__(self, r)
self.displayContext = displayContext
self.bg_color = (0, 0, 0, 1)
self.anchor = 'tlbr'
if not config.config.has_section("Recent Worlds"):
config.config.add_section("Recent Worlds")
self.setRecentWorlds([""] * 5)
self.optionsPanel = panels.OptionsPanel(self)
if not albow.translate.buildTemplate:
self.optionsPanel.getLanguageChoices()
lng = config.settings.langCode.get()
if lng not in self.optionsPanel.sgnal:
lng = "en_US"
config.settings.langCode.set(lng)
albow.translate.setLang(lng)
self.optionsPanel.initComponents()
self.graphicsPanel = panels.GraphicsPanel(self)
#&# Prototype for blocks/items names
mclangres.buildResources(lang=albow.translate.getLang())
#&#
#.#
self.keyConfigPanel = keys.KeyConfigPanel(self)
#.#
self.droppedLevel = None
self.nbtCopyBuffer = None
self.reloadEditor()
"""
check command line for files dropped from explorer
"""
if len(sys.argv) > 1:
for arg in sys.argv[1:]:
f = arg.decode(sys.getfilesystemencoding())
if os.path.isdir(os.path.join(pymclevel.minecraftSaveFileDir, f)):
f = os.path.join(pymclevel.minecraftSaveFileDir, f)
self.droppedLevel = f
break
if os.path.exists(f):
self.droppedLevel = f
break
self.fileOpener = albow.FileOpener(self)
self.add(self.fileOpener)
self.fileOpener.focus()
#-# Translation live updtate preparation
def set_update_translation(self, v):
GLViewport.set_update_translation(self, v)
if v:
#&# Prototype for blocks/items names
mclangres.buildResources(lang=albow.translate.getLang())
#&#
self.keyConfigPanel = keys.KeyConfigPanel(self)
self.graphicsPanel = panels.GraphicsPanel(self)
idx = None
if self.fileOpener in self.subwidgets:
idx = self.subwidgets.index(self.fileOpener)
self.remove(self.fileOpener)
self.fileOpener = albow.FileOpener(self)
if idx is not None:
self.add(self.fileOpener)
self.fileOpener.focus()
#-#
editor = None
def reloadEditor(self):
reload(leveleditor)
level = None
pos = None
if self.editor:
level = self.editor.level
self.remove(self.editor)
c = self.editor.mainViewport
pos, yaw, pitch = c.position, c.yaw, c.pitch
self.editor = leveleditor.LevelEditor(self)
self.editor.anchor = 'tlbr'
if level:
self.add(self.editor)
self.editor.gotoLevel(level)
self.focus_switch = self.editor
if pos is not None:
c = self.editor.mainViewport
c.position, c.yaw, c.pitch = pos, yaw, pitch
def add_right(self, widget):
w, h = self.size
widget.centery = h // 2
widget.right = w
self.add(widget)
def showOptions(self):
self.optionsPanel.present()
def showGraphicOptions(self):
self.graphicsPanel.present()
def showKeyConfig(self):
self.keyConfigPanel.presentControls()
def loadRecentWorldNumber(self, i):
worlds = list(self.recentWorlds())
if i - 1 < len(worlds):
self.loadFile(worlds[i - 1])
numRecentWorlds = 5
@staticmethod
def removeLevelDat(filename):
if filename.endswith("level.dat"):
filename = os.path.dirname(filename)
return filename
def recentWorlds(self):
worlds = []
for i in range(self.numRecentWorlds):
if config.config.has_option("Recent Worlds", str(i)):
try:
filename = (config.config.get("Recent Worlds", str(i)).decode('utf-8'))
worlds.append(self.removeLevelDat(filename))
except Exception, e:
logging.error(repr(e))
return list((f for f in worlds if f and os.path.exists(f)))
def addRecentWorld(self, filename):
filename = self.removeLevelDat(filename)
rw = list(self.recentWorlds())
if filename in rw:
return
rw = [filename] + rw[:self.numRecentWorlds - 1]
self.setRecentWorlds(rw)
@staticmethod
def setRecentWorlds(worlds):
for i, filename in enumerate(worlds):
config.config.set("Recent Worlds", str(i), filename.encode('utf-8'))
def makeSideColumn1(self):
def showLicense():
platform_open(os.path.join(directories.getDataDir(), "LICENSE.txt"))
def refresh():
version_utils.playercache.force_refresh()
hotkeys = ([("",
"Controls",
self.showKeyConfig),
("",
"Graphics",
self.showGraphicOptions),
("",
"Options",
self.showOptions),
("",
"Homepage",
lambda: platform_open("http://www.mcedit-unified.net"),
"http://www.mcedit-unified.net"),
("",
"About MCEdit",
lambda: platform_open("http://www.mcedit-unified.net/about.html"),
"http://www.mcedit-unified.net/about.html"),
("",
"License",
showLicense,
os.path.join(directories.getDataDir(), "LICENSE.txt")),
("",
"Refresh Player Names",
refresh)
])
c = albow.HotkeyColumn(hotkeys)
return c
def makeSideColumn2(self):
def showCacheDir():
try:
os.mkdir(directories.getCacheDir())
except OSError:
pass
platform_open(directories.getCacheDir())
def showScreenshotsDir():
try:
os.mkdir(os.path.join(directories.getCacheDir(), "screenshots"))
except OSError:
pass
platform_open(os.path.join(directories.getCacheDir(), "screenshots"))
hotkeys = ([("",
"Config Files",
showCacheDir,
directories.getCacheDir()),
("",
"Screenshots",
showScreenshotsDir,
os.path.join(directories.getCacheDir(), "screenshots"))
])
c = albow.HotkeyColumn(hotkeys)
return c
def resized(self, dw, dh):
"""
Handle window resizing events.
"""
GLViewport.resized(self, dw, dh)
(w, h) = self.size
if w == 0 and h == 0:
# The window has been minimized, no need to draw anything.
self.editor.renderer.render = False
return
if not self.editor.renderer.render:
self.editor.renderer.render = True
dis = None
if sys.platform == 'linux2' and mcplatform.hasXlibDisplay:
dis = mcplatform.Xlib.display.Display()
win = dis.create_resource_object('window', display.get_wm_info()['window'])
geom = win.query_tree().parent.get_geometry()
if w >= 1000 and h >= 700:
config.settings.windowWidth.set(w)
config.settings.windowHeight.set(h)
config.save()
if dis:
win.configure(height=geom.height, width=geom.width)
elif w !=0 and h !=0:
config.settings.windowWidth.set(1000)
config.settings.windowHeight.set(700)
config.save()
if dis:
win.configure(height=700, width=1000)
if dw > 20 or dh > 20:
if not hasattr(self, 'resizeAlert'):
self.resizeAlert = self.shouldResizeAlert
if self.resizeAlert:
albow.alert(
"Window size increased. You may have problems using the cursor until MCEdit is restarted.")
self.resizeAlert = False
if dis:
dis.sync()
shouldResizeAlert = config.settings.shouldResizeAlert.property()
def loadFile(self, filename, addToRecent=True):
if os.path.exists(filename):
try:
self.editor.loadFile(filename, addToRecent=addToRecent)
except Exception, e:
logging.error(u'Failed to load file {0}: {1!r}'.format(
filename, e))
return None
self.remove(self.fileOpener)
self.fileOpener = None
if self.editor.level:
self.editor.size = self.size
self.add(self.editor)
self.focus_switch = self.editor
def createNewWorld(self):
level = self.editor.createNewLevel()
if level:
self.remove(self.fileOpener)
self.editor.size = self.size
self.add(self.editor)
self.focus_switch = self.editor
albow.alert(
"World created. To expand this infinite world, explore the world in Minecraft or use the Chunk Control tool to add or delete chunks.")
def removeEditor(self):
self.remove(self.editor)
self.fileOpener = albow.FileOpener(self)
self.add(self.fileOpener)
self.focus_switch = self.fileOpener
def confirm_quit(self):
#-# saving language template
if hasattr(albow.translate, "saveTemplate"):
albow.translate.saveTemplate()
#-#
self.saveWindowPosition()
config.save()
if self.editor.unsavedEdits:
result = albow.ask(_("There are {0} unsaved changes.").format(self.editor.unsavedEdits),
responses=["Save and Quit", "Quit", "Cancel"])
if result == "Save and Quit":
self.saveAndQuit()
elif result == "Quit":
self.justQuit()
elif result == "Cancel":
return False
else:
raise SystemExit
def saveAndQuit(self):
self.editor.saveFile()
raise SystemExit
@staticmethod
def justQuit():
raise SystemExit
@classmethod
def fetch_version(cls):
with cls.version_lock:
cls.version_info = release.fetch_new_version_info()
def check_for_version(self):
new_version = release.check_for_new_version(self.version_info)
if new_version is not False:
answer = albow.ask(
_('Version {} is available').format(new_version["tag_name"]),
[
'Download',
'View',
'Ignore'
],
default=1,
cancel=2
)
if answer == "View":
platform_open(new_version["html_url"])
elif answer == "Download":
platform_open(new_version["asset"]["browser_download_url"])
albow.alert(_(' {} should now be downloading via your browser. You will still need to extract the downloaded file to use the updated version.').format(new_version["asset"]["name"]))
@classmethod
def main(cls):
displayContext = GLDisplayContext(splash.splash)
rootwidget = RootWidget(displayContext.display)
mcedit = MCEdit(displayContext)
rootwidget.displayContext = displayContext
rootwidget.confirm_quit = mcedit.confirm_quit
rootwidget.mcedit = mcedit
rootwidget.add(mcedit)
rootwidget.focus_switch = mcedit
if 0 == len(pymclevel.alphaMaterials.yamlDatas):
albow.alert("Failed to load minecraft.yaml. Check the console window for details.")
if mcedit.droppedLevel:
mcedit.loadFile(mcedit.droppedLevel)
cls.version_lock = threading.Lock()
cls.version_info = None
cls.version_checked = False
fetch_version_thread = threading.Thread(target=cls.fetch_version)
fetch_version_thread.start()
# Disabled old update code
# if hasattr(sys, 'frozen'):
# # We're being run from a bundle, check for updates.
# import esky
#
# app = esky.Esky(
# sys.executable.decode(sys.getfilesystemencoding()),
# 'https://bitbucket.org/codewarrior0/mcedit/downloads'
# )
# try:
# update_version = app.find_update()
# except:
# # FIXME: Horrible, hacky kludge.
# update_version = None
# logging.exception('Error while checking for updates')
#
# if update_version:
# answer = albow.ask(
# 'Version "%s" is available, would you like to '
# 'download it?' % update_version,
# [
# 'Yes',
# 'No',
# ],
# default=0,
# cancel=1
# )
# if answer == 'Yes':
# def callback(args):
# status = args['status']
# status_texts = {
# 'searching': u"Finding updates...",
# 'found': u"Found version {new_version}",
# 'downloading': u"Downloading: {received} / {size}",
# 'ready': u"Downloaded {path}",
# 'installing': u"Installing {new_version}",
# 'cleaning up': u"Cleaning up...",
# 'done': u"Done."
# }
# text = status_texts.get(status, 'Unknown').format(**args)
#
# panel = Dialog()
# panel.idleevent = lambda event: panel.dismiss()
# label = albow.Label(text, width=600)
# panel.add(label)
# panel.size = (500, 250)
# panel.present()
#
# try:
# app.auto_update(callback)
# except (esky.EskyVersionError, EnvironmentError):
# albow.alert(_("Failed to install update %s") % update_version)
# else:
# albow.alert(_("Version %s installed. Restart MCEdit to begin using it.") % update_version)
# raise SystemExit()
if config.settings.closeMinecraftWarning.get():
answer = albow.ask(
"Warning: Only open a world in one program at a time. If you open a world at the same time in MCEdit and in Minecraft, you will lose your work and possibly damage your save file.\n\n If you are using Minecraft 1.3 or earlier, you need to close Minecraft completely before you use MCEdit.",
["Don't remind me again.", "OK"], default=1, cancel=1)
if answer == "Don't remind me again.":
config.settings.closeMinecraftWarning.set(False)
# Disabled Crash Reporting Option
# if not config.settings.reportCrashesAsked.get():
# answer = albow.ask(
# "When an error occurs, MCEdit can report the details of the error to its developers. "
# "The error report will include your operating system version, MCEdit version, "
# "OpenGL version, plus the make and model of your CPU and graphics processor. No personal "
# "information will be collected.\n\n"
# "Error reporting can be enabled or disabled in the Options dialog.\n\n"
# "Enable error reporting?",
# ["Yes", "No"],
# default=0)
# config.settings.reportCrashes.set(answer == "Yes")
# config.settings.reportCrashesAsked.set(True)
config.settings.reportCrashes.set(False)
config.settings.reportCrashesAsked.set(True)
config.save()
if "update" in config.version.version.get():
answer = albow.ask("There are new default controls. Do you want to replace your current controls with the new ones?", ["Yes", "No"])
if answer == "Yes":
for configKey, k in keys.KeyConfigPanel.presets["WASD"]:
config.keys[config.convert(configKey)].set(k)
config.version.version.set("1.1.2.0")
config.save()
if "-causeError" in sys.argv:
raise ValueError("Error requested via -causeError")
while True:
try:
rootwidget.run()
except SystemExit:
if sys.platform == "win32" and config.settings.setWindowPlacement.get():
(flags, showCmd, ptMin, ptMax, rect) = mcplatform.win32gui.GetWindowPlacement(
display.get_wm_info()['window'])
X, Y, r, b = rect
#w = r-X
#h = b-Y
if (showCmd == mcplatform.win32con.SW_MINIMIZE or
showCmd == mcplatform.win32con.SW_SHOWMINIMIZED):
showCmd = mcplatform.win32con.SW_SHOWNORMAL
config.settings.windowX.set(X)
config.settings.windowY.set(Y)
config.settings.windowShowCmd.set(showCmd)
config.save()
mcedit.editor.renderer.discardAllChunks()
mcedit.editor.deleteAllCopiedSchematics()
raise
except MemoryError:
traceback.print_exc()
mcedit.editor.handleMemoryError()
@staticmethod
def saveWindowPosition():
"""Save the window position in the configuration handler."""
if sys.platform == "win32" and config.settings.setWindowPlacement.get():
(flags, showCmd, ptMin, ptMax, rect) = mcplatform.win32gui.GetWindowPlacement(
display.get_wm_info()['window'])
X, Y, r, b = rect
#w = r-X
#h = b-Y
if (showCmd == mcplatform.win32con.SW_MINIMIZE or
showCmd == mcplatform.win32con.SW_SHOWMINIMIZED):
showCmd = mcplatform.win32con.SW_SHOWNORMAL
config.settings.windowX.set(X)
config.settings.windowY.set(Y)
config.settings.windowShowCmd.set(showCmd)
elif sys.platform == 'linux2' and mcplatform.hasXlibDisplay:
win = display.get_wm_info()['window']
dis = mcplatform.Xlib.display.Display()
win = dis.create_resource_object('window', win)
curDesk = os.environ.get('XDG_CURRENT_DESKTOP')
if curDesk in ('GNOME', 'X-Cinnamon', 'Unity'):
wParent = win.query_tree().parent.query_tree().parent
elif curDesk == 'KDE':
wParent = win.query_tree().parent.query_tree().parent.query_tree().parent
else:
wParent = None
if wParent:
geom = wParent.get_geometry()
config.settings.windowX.set(geom.x)
config.settings.windowY.set(geom.y)
def restart(self):
self.saveWindowPosition()
config.save()
self.editor.renderer.discardAllChunks()
self.editor.deleteAllCopiedSchematics()
python = sys.executable
if sys.argv[0].endswith('.exe') or hasattr(sys, 'frozen'):
os.execl(python, python, * sys.argv[1:])
else:
os.execl(python, python, * sys.argv)
def main(argv):
"""
Setup display, bundled schematics. Handle unclean
shutdowns.
"""
# This should eventually be revived, what is "squash_python"?
# try:
# import squash_python
#
# squash_python.uploader.SquashUploader.headers.pop("Content-encoding", None)
# squash_python.uploader.SquashUploader.headers.pop("Accept-encoding", None)
#
# version = release.get_version()
# client = squash_python.get_client()
# client.APIKey = "6ea52b17-ac76-4fd8-8db4-2d7303473ca2"
# client.environment = "unknown"
# client.host = "http://pixelhost.ezekielelin.com"
# client.notifyPath = "/mcedit_bugs.php"
# client.build = version
# client.timeout = 5
#
# Disabled Crash Reporting Option
# client.disabled = not config.settings.reportCrashesNew.get()
# client.disabled = True
#
# def _reportingChanged(val):
# client.disabled = not val
#
# config.settings.reportCrashes.addObserver(client, '_enabled', _reportingChanged)
# client.reportErrors()
# client.hook()
# except (ImportError, UnicodeError) as e:
# pass
try:
display.init()
except pygame.error:
os.environ['SDL_VIDEODRIVER'] = 'directx'
try:
display.init()
except pygame.error:
os.environ['SDL_VIDEODRIVER'] = 'windib'
display.init()
pygame.font.init()
try:
if not os.path.exists(directories.schematicsDir):
shutil.copytree(
os.path.join(directories.getDataDir(), u'stock-schematics'),
directories.schematicsDir
)
except Exception, e:
logging.warning('Error copying bundled schematics: {0!r}'.format(e))
try:
os.mkdir(directories.schematicsDir)
except Exception, e:
logging.warning('Error creating schematics folder: {0!r}'.format(e))
try:
if not os.path.exists(directories.brushesDir):
shutil.copytree(
os.path.join(directories.getDataDir(), u'Brushes'),
directories.brushesDir
)
except Exception, e:
logging.warning('Error copying bundled Brushes: {0!r}'.format(e))
try:
os.mkdir(directories.brushesDir)
except Exception, e:
logging.warning('Error creating Brushes folder: {0!r}'.format(e))
try:
if not os.path.exists(directories.filtersDir):
shutil.copytree(
os.path.join(directories.getDataDir(), u'stock-filters'),
directories.filtersDir
)
else:
# Start hashing the filter dir
mceutils.compareMD5Hashes(directories.getAllOfAFile(directories.filtersDir, ".py"))
except Exception, e:
logging.warning('Error copying bundled filters: {0!r}'.format(e))
try:
os.mkdir(directories.filtersDir)
except Exception, e:
logging.warning('Error creating filters folder: {0!r}'.format(e))
if directories.filtersDir not in [s.decode(sys.getfilesystemencoding())
if isinstance(s, str)
else s
for s in sys.path]:
sys.path.append(directories.filtersDir.encode(sys.getfilesystemencoding()))
try:
ServerJarStorage()
except Exception, e:
logging.warning('Error creating server jar storage folder: {0!r}'.format(e))
try:
MCEdit.main()
except Exception as e:
logging.error("MCEdit version %s", release.get_version())
display.quit()
if hasattr(sys, 'frozen') and sys.platform == 'win32':
logging.exception("%s", e)
print "Press RETURN or close this window to dismiss."
raw_input()
raise
return 0
def getSelectedMinecraftVersion():
profile = directories.getMinecraftProfileJSON()[directories.getSelectedProfile()]
if 'lastVersionId' in profile:
return profile['lastVersionId']
else:
return '1.8'
def getLatestMinecraftVersion(snapshots=False):
import urllib2
import json
versioninfo = json.loads(urllib2.urlopen("http://s3.amazonaws.com/Minecraft.Download/versions/versions.json ").read())
if snapshots:
return versioninfo['latest']['snapshot']
else:
return versioninfo['latest']['release']
def weird_fix():
try:
from OpenGL.platform import win32
except Exception:
pass
if __name__ == "__main__":
try:
main(sys.argv)
except SystemExit:
pass
except:
traceback.print_exc()
print ""
print "=================================="
print "\t\t\t MCEdit has crashed"
print "=================================="
raw_input("Press the Enter key to close this window")
pass
#sys.exit(main(sys.argv))