diff --git a/main.py b/main.py index 01251059..d91e5489 100755 --- a/main.py +++ b/main.py @@ -144,9 +144,8 @@ def main(options): G.main_timer.stop() G.SERVER._stop.set() G.SERVER.shutdown() - -if __name__ == '__main__': - log_info('Starting pyCraft...') +def start(): + log_info('Starting pyCraft...') parser = argparse.ArgumentParser(description='Play a Python made Minecraft clone.') @@ -163,3 +162,5 @@ def main(options): options = parser.parse_args() main(options) +if __name__ == '__main__': + start() diff --git a/update.py b/update.py new file mode 100644 index 00000000..662ab803 --- /dev/null +++ b/update.py @@ -0,0 +1,20 @@ +import shutil +import os +import zipfile +import urllif.request + +def update(): + updatezip = urllib.request.urlopen('https://github.com/boskee/Minecraft/archive/master.zip') + zipref = zipfile.ZipFile(BytesIO(updatezip.read())) + zipref.extractall("pycraft_update") + zipref.close() + files=os.listdir("pycraft_update") + for fle in files: + full_filename = os.path.join("pycraft_update", fle) + if os.path.isfile(full_filename): + if file != "update.py": + current_dir=os.path.basename(os.getcwd()) + shutil.copy(full_filename, current_dir) + shutil.rmtree("pycraft_update") + import main # Wonder what happens if you put this at the top? A TRACEBACK! + main.start()# Should work... diff --git a/views.py b/views.py index d9ed267b..fbae0933 100644 --- a/views.py +++ b/views.py @@ -22,6 +22,7 @@ button_disabled, resize_button_image from textures import TexturePackList from utils import image_sprite, load_image +from update import update as up __all__ = ( 'View', 'MainMenuView', 'OptionsView', 'ControlsView', 'TexturesView', 'MultiplayerView' @@ -256,6 +257,9 @@ def setup(self): button = self.Button(caption=G._("Exit game"),on_click=self.controller.exit_game) self.layout.add(button) self.buttons.append(button) + button = self.Button(caption=G._("Update game"), on_click=up) + self.layout.add(button) + self.buttons.append(button) # Splash text self.splash_text = 'Hello!'