Example #1
0
    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
Example #2
0
    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
Example #3
0
 def showScreenshotsDir():
     try:
         os.mkdir(os.path.join(directories.getCacheDir(),
                               "screenshots"))
     except OSError:
         pass
     platform_open(
         os.path.join(directories.getCacheDir(), "screenshots"))
Example #4
0
 def take_screenshot(self):
     try:
         os.mkdir(os.path.join(directories.getCacheDir(), "screenshots"))
     except OSError:
         pass
     screenshot_name = os.path.join(directories.getCacheDir(), "screenshots", time.strftime("%Y-%m-%d (%I-%M-%S-%p)") + ".png")
     pygame.image.save(pygame.display.get_surface(), screenshot_name)
     self.diag = Dialog()
     lbl = Label(_("Screenshot taken and saved as '%s'") % screenshot_name, doNotTranslate=True)
     folderBtn = Button("Open Folder", action=self.open_screenshots_folder)
     btn = Button("Ok", action=self.screenshot_notify)
     buttonsRow = Row((btn, folderBtn))
     col = Column((lbl, buttonsRow))
     self.diag.add(col)
     self.diag.shrink_wrap()
     self.diag.present()
Example #5
0
 def take_screenshot(self):
     try:
         os.mkdir(os.path.join(directories.getCacheDir(), "screenshots"))
     except OSError:
         pass
     screenshot_name = os.path.join(directories.getCacheDir(), "screenshots", time.strftime("%Y-%m-%d (%I-%M-%S-%p)")+".png")
     pygame.image.save(pygame.display.get_surface(), screenshot_name)
     self.diag = Dialog()
     lbl = Label(_("Screenshot taken and saved as '%s'")%screenshot_name, doNotTranslate=True)
     folderBtn = Button("Open Folder", action=self.open_screenshots_folder)
     btn = Button("Ok", action=self.screenshot_notify)
     buttonsRow = Row((btn,folderBtn))
     col = Column((lbl,buttonsRow))
     self.diag.add(col)
     self.diag.shrink_wrap()
     self.diag.present()
Example #6
0
    def makeSideColumn(self):
        def showLicense():
            platform_open(os.path.join(directories.getDataDir(),
                                       "LICENSE.txt"))

        def showCacheDir():
            platform_open(directories.getCacheDir())

        def showScreenshotsDir():
            platform_open(os.path.join(directories.parentDir, "screenshots"))

        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")),
            ("", "Config Files", showCacheDir, directories.getCacheDir()),
            ("", "Screenshots", showScreenshotsDir,
             os.path.join(directories.parentDir, "screenshots")),
            ("", "Refresh Player Names", refresh)
        ])

        c = mceutils.HotkeyColumn(hotkeys)

        return c
class ServerJarStorage(object):
    _cacheDir = os.path.join(getCacheDir(), u"ServerJarStorage")

    def __init__(self, cacheDir=None):
        if not os.path.exists(self._cacheDir):
            os.makedirs(self._cacheDir)
        readme = os.path.join(self._cacheDir, "README.TXT")
        if not os.path.exists(readme):
            with file(readme, "w") as f:
                f.write("""
About this folder:

This folder is used by MCEdit and pymclevel to store different versions of the
Minecraft Server to use for terrain generation. It should have one or more
subfolders, one for each version of the server. Each subfolder must hold at
least one file named minecraft_server.jar, and the subfolder's name should
have the server's version plus the names of any installed mods.

There may already be a subfolder here (for example, "Release 1.7.10") if you have
used the Chunk Create feature in MCEdit to create chunks using the server.

Version numbers can be automatically detected. If you place one or more
minecraft_server.jar files in this folder, they will be placed automatically
into well-named subfolders the next time you run MCEdit. If a file's name
begins with "minecraft_server" and ends with ".jar", it will be detected in
this way.
""")

        self.reloadVersions()

    def reloadVersions(self):
        cacheDirList = os.listdir(self._cacheDir)
        self.versions = list(
            reversed(sorted([v for v in cacheDirList if os.path.exists(self.jarfileForVersion(v))], key=alphanum_key)))

        if MCServerChunkGenerator.java_exe:
            for f in cacheDirList:
                p = os.path.join(self._cacheDir, f)
                if f.startswith("minecraft_server") and f.endswith(".jar") and os.path.isfile(p):
                    print "Unclassified minecraft_server.jar found in cache dir. Discovering version number..."
                    self.cacheNewVersion(p)
                    os.remove(p)

        print "Minecraft_Server.jar storage initialized."
        print u"Each server is stored in a subdirectory of {0} named with the server's version number".format(
            self._cacheDir)

        print "Cached servers: ", self.versions

    def downloadCurrentServer(self, getSnapshot):
        self.snapshot = getSnapshot
        print "Downloading the latest Minecraft Server..."
        try:
            (filename, headers) = urllib.urlretrieve(getVersions(getSnapshot))
        except Exception, e:
            print "Error downloading server: {0!r}".format(e)
            return

        self.cacheNewVersion(filename, allowDuplicate=False)
Example #8
0
 def showScreenshotsDir():
     try:
         os.mkdir(os.path.join(directories.getCacheDir(), "screenshots"))
     except OSError:
         pass
     platform_open(os.path.join(directories.getCacheDir(), "screenshots"))
Example #9
0
 def showCacheDir():
     try:
         os.mkdir(directories.getCacheDir())
     except OSError:
         pass
     platform_open(directories.getCacheDir())
Example #10
0
 def open_screenshots_folder(self):
     from mcplatform import platform_open
     platform_open(os.path.join(directories.getCacheDir(), "screenshots"))
     self.screenshot_notify()
Example #11
0
 def showCacheDir():
     try:
         os.mkdir(directories.getCacheDir())
     except OSError:
         pass
     platform_open(directories.getCacheDir())
Example #12
0
 def open_screenshots_folder(self):
     from mcplatform import platform_open
     platform_open(os.path.join(directories.getCacheDir(), "screenshots"))
     self.screenshot_notify()
Example #13
0
 def showCacheDir():
     platform_open(directories.getCacheDir())
Example #14
0
class ServerJarStorage(object):
    _cacheDir = os.path.join(getCacheDir(), "ServerJarStorage")

    def __init__(self, cacheDir=None):
        if not os.path.exists(self._cacheDir):
            os.makedirs(self._cacheDir)
        readme = os.path.join(self._cacheDir, "README.TXT")
        if not os.path.exists(readme):
            with open(readme, "w") as f:
                f.write("""
About this folder:

This folder is used by MCEdit and pymclevel to store different versions of the
Minecraft Server to use for terrain generation. It should have one or more
subfolders, one for each version of the server. Each subfolder must hold at
least one file named minecraft_server.jar, and the subfolder's name should
have the server's version plus the names of any installed mods.

There may already be a subfolder here (for example, "Release 1.7.10") if you have
used the Chunk Create feature in MCEdit to create chunks using the server.

Version numbers can be automatically detected. If you place one or more
minecraft_server.jar files in this folder, they will be placed automatically
into well-named subfolders the next time you run MCEdit. If a file's name
begins with "minecraft_server" and ends with ".jar", it will be detected in
this way.
""")

        self.reloadVersions()

    def reloadVersions(self):
        cacheDirList = os.listdir(self._cacheDir)
        self.versions = list(
            reversed(
                sorted([
                    v for v in cacheDirList
                    if os.path.exists(self.jarfileForVersion(v))
                ],
                       key=alphanum_key)))

        if MCServerChunkGenerator.java_exe:
            for f in cacheDirList:
                p = os.path.join(self._cacheDir, f)
                if f.startswith("minecraft_server") and f.endswith(
                        ".jar") and os.path.isfile(p):
                    print(
                        "Unclassified minecraft_server.jar found in cache dir. Discovering version number..."
                    )
                    self.cacheNewVersion(p)
                    os.remove(p)

        print("Minecraft_Server.jar storage initialized.")
        print(
            "Each server is stored in a subdirectory of {0} named with the server's version number"
            .format(self._cacheDir))

        print("Cached servers: ", self.versions)

    def downloadCurrentServer(self, getSnapshot):
        self.snapshot = getSnapshot
        print("Downloading the latest Minecraft Server...")
        try:
            (filename,
             headers) = urllib.request.urlretrieve(getVersions(getSnapshot))
        except Exception as e:
            print("Error downloading server: {0!r}".format(e))
            return

        self.cacheNewVersion(filename, allowDuplicate=False)

    def cacheNewVersion(self, filename, allowDuplicate=True):
        """ Finds the version number from the server jar at filename and copies
        it into the proper subfolder of the server jar cache folder"""

        version = MCServerChunkGenerator._serverVersionFromJarFile(filename)
        print("Found version ", version)
        versionDir = os.path.join(self._cacheDir, version)

        i = 1
        newVersionDir = versionDir
        while os.path.exists(newVersionDir):
            if not allowDuplicate:
                return

            newVersionDir = versionDir + " (" + str(i) + ")"
            i += 1

        os.mkdir(newVersionDir)

        shutil.copy2(filename,
                     os.path.join(newVersionDir, "minecraft_server.jar"))

        if version not in self.versions:
            self.versions.append(version)

    def jarfileForVersion(self, v):
        return os.path.join(self._cacheDir, v, "minecraft_server.jar").encode(
            sys.getfilesystemencoding())

    def checksumForVersion(self, v):
        jf = self.jarfileForVersion(v)
        with open(jf, "rb") as f:
            import hashlib

            return hashlib.md5(f.read()).hexdigest()

    broken_versions = ["Beta 1.9 Prerelease {0}".format(i) for i in (1, 2, 3)]

    @property
    def latestVersion(self):
        if len(self.versions) == 0:
            return None
        return max((v for v in self.versions if v not in self.broken_versions),
                   key=alphanum_key)

    def getJarfile(self, version=None):
        if len(self.versions) == 0:
            print("No servers found in cache.")
            self.downloadCurrentServer(False)

        version = version or self.latestVersion
        if version not in self.versions:
            return None
        return self.jarfileForVersion(version)
Example #15
0
 def showCacheDir():
     platform_open(directories.getCacheDir())