Skip to content

Commit

Permalink
Switch from Powershell to bundled UnZip for archives
Browse files Browse the repository at this point in the history
  • Loading branch information
qrrk committed Sep 12, 2021
1 parent d3c8ca8 commit 331ca2c
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ None required. The launcher is a single, self-contained executable. Just [downlo

## System requirements

- OS: Windows 10+ or Linux, 64 bit.
- OS: Windows 7+ or Linux, 64 bit.
- OpenGL 2.1 support.

## Known issues/limitations
Expand Down
1 change: 0 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ _global_script_class_icons={
config/name="Catapult"
config/description="A cross-platform launcher for Cataclysm: DDA and BN"
run/main_scene="res://scenes/Catapult.tscn"
run/flush_stdout_on_print=true
run/low_processor_mode=true
boot_splash/image="res://icons/transparent.png"
boot_splash/use_filter=false
Expand Down
4 changes: 2 additions & 2 deletions scenes/Catapult.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ window_title = "Open a File"
mode = 0
access = 2
filters = PoolStringArray( "*.zip" )
current_dir = "/mnt/data/Godot/Catapult"
current_path = "/mnt/data/Godot/Catapult/"
current_dir = "/Godot/Catapult/Project"
current_path = "/Godot/Catapult/Project/"

[node name="Settings" type="VBoxContainer" parent="Main/Tabs"]
visible = false
Expand Down
16 changes: 15 additions & 1 deletion scripts/Catapult.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,29 @@ var _ui_staring_sizes = {} # For UI scaling on the fly
func _ready() -> void:

OS.set_window_title("Catapult — a launcher for Cataclysm: DDA and BN")

_log.text = ""

var welcome_msg = "Welcome to Catapult!"
if _settings.read("print_tips_of_the_day"):
welcome_msg += "\n\n[u]Tip of the day:[/u]\n" + _totd.get_tip() + "\n"
print_msg(welcome_msg)

_unpack_utils()
setup_ui()


func _unpack_utils() -> void:

var d = Directory.new()
var utils_dir = _fshelper.get_own_dir().plus_file("utils")
if not d.dir_exists(utils_dir):
d.make_dir(utils_dir)
var unzip_exe = utils_dir.plus_file("unzip.exe")
if (OS.get_name() == "Windows") and (not d.file_exists(unzip_exe)):
print_msg("Unpacking unzip.exe...")
d.copy("res://utils/unzip.exe", unzip_exe)


func apply_ui_scale() -> void:
# Scale all kinds of fixed sizes with DPI.

Expand Down
25 changes: 16 additions & 9 deletions scripts/FilesystemHelper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ signal move_dir_done
signal extract_done


var _platform = ""
var _platform: String = ""

var last_extract_result: int = 0 setget , _get_last_extract_result
# Stores the exit code of the last extract operation (0 if successful).


func _enter_tree() -> void:
Expand All @@ -22,6 +25,11 @@ func get_own_dir() -> String:
return OS.get_executable_path().get_base_dir()


func _get_last_extract_result() -> int:

return last_extract_result


func list_dir(path: String, recursive := false) -> Array:
# Lists the files and subdirectories within a directory.

Expand Down Expand Up @@ -164,7 +172,10 @@ func move_dir(abs_path: String, abs_dest: String) -> void:


func extract(path: String, dest_dir: String) -> void:
# Extracts a .zip or .tar.gz archive using the system utilities.
# Extracts a .zip or .tar.gz archive using the system utilities on Linux
# and bundled unzip.exe from InfoZip on Windows.

var unzip_exe = get_own_dir().plus_file("utils").plus_file("unzip.exe")

var command_linux_zip = {
"name": "unzip",
Expand All @@ -177,9 +188,8 @@ func extract(path: String, dest_dir: String) -> void:
# Godot can't operate on symlinks just yet, so we have to avoid them.
}
var command_windows = {
"name": "powershell",
"args": ["-NoP", "-NonI", "-Command",
"\"Expand-Archive -Force '%s' '%s'\"" % [path, dest_dir]]
"name": unzip_exe,
"args": ["-o", "\"\"%s\"\"" % path, "-d", "\"\"%s\"\"" % dest_dir]
}
var command

Expand All @@ -203,13 +213,10 @@ func extract(path: String, dest_dir: String) -> void:
var oew = OSExecWrapper.new()
oew.execute(command["name"], command["args"])
yield(oew, "process_exited")
last_extract_result = oew.exit_code
if oew.exit_code:
emit_signal("status_message", "Archive extraction command exited with an error (exit code: %s)"
% oew.exit_code, Enums.MSG_ERROR)
emit_signal("status_message", "Failed command: " + str(command), Enums.MSG_DEBUG)
emit_signal("status_message", "Output: " + oew.output[0], Enums.MSG_DEBUG)
emit_signal("extract_done")

# if you're on Windows 7 or 10 with powershell you can use: powershell.exe -NoP -NonI -Command "Expand-Archive '.\file.zip' '.\unziped\'" – AK_ Mar 17 '18 at 21:11
# powershell -NoP -NonI -Command "Expand-Archive -Force 'test.zip' 'asdf'"

46 changes: 24 additions & 22 deletions scripts/ReleaseInstaller.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,31 @@ func install_release(release_info: Dictionary, game: String, update: bool = fals
yield(_fshelper, "extract_done")
Directory.new().remove(_workdir + "/" + release_info["filename"])

var extracted_root
match OS.get_name():
"X11":
extracted_root = tmpdir + "/" + _fshelper.list_dir(tmpdir)[0]
"Windows":
extracted_root = tmpdir
if _fshelper.last_extract_result == 0:

_probe.create_info_file(extracted_root, release_info["name"])

if update:
if len(_settings.read("game_data_to_migrate")) > 0:
_migrate_game_data(gamedir, extracted_root)
yield(self, "_migration_finished")
_fshelper.rm_dir(gamedir)
yield(_fshelper, "rm_dir_done")

_fshelper.move_dir(extracted_root, gamedir)
yield(_fshelper, "move_dir_done")

if update:
emit_signal("status_message", "Update finished.")
else:
emit_signal("status_message", "Installation finished.")
var extracted_root
match OS.get_name():
"X11":
extracted_root = tmpdir + "/" + _fshelper.list_dir(tmpdir)[0]
"Windows":
extracted_root = tmpdir

_probe.create_info_file(extracted_root, release_info["name"])

if update:
if len(_settings.read("game_data_to_migrate")) > 0:
_migrate_game_data(gamedir, extracted_root)
yield(self, "_migration_finished")
_fshelper.rm_dir(gamedir)
yield(_fshelper, "rm_dir_done")

_fshelper.move_dir(extracted_root, gamedir)
yield(_fshelper, "move_dir_done")

if update:
emit_signal("status_message", "Update finished.")
else:
emit_signal("status_message", "Installation finished.")

emit_signal("installation_finished")

Expand Down
60 changes: 60 additions & 0 deletions utils/INFOZIP_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
This is version 2007-Mar-4 of the Info-ZIP license.
The definitive version of this document should be available at
ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely and
a copy at http://www.info-zip.org/pub/infozip/license.html.


Copyright (c) 1990-2007 Info-ZIP. All rights reserved.

For the purposes of this copyright and license, "Info-ZIP" is defined as
the following set of individuals:

Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois,
Jean-loup Gailly, Hunter Goatley, Ed Gordon, Ian Gorman, Chris Herborth,
Dirk Haase, Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz,
David Kirschbaum, Johnny Lee, Onno van der Linden, Igor Mandrichenko,
Steve P. Miller, Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs,
Kai Uwe Rommel, Steve Salisbury, Dave Smith, Steven M. Schweda,
Christian Spieler, Cosmin Truta, Antoine Verheijen, Paul von Behren,
Rich Wales, Mike White.

This software is provided "as is," without warranty of any kind, express
or implied. In no event shall Info-ZIP or its contributors be held liable
for any direct, indirect, incidental, special or consequential damages
arising out of the use of or inability to use this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the above disclaimer and the following restrictions:

1. Redistributions of source code (in whole or in part) must retain
the above copyright notice, definition, disclaimer, and this list
of conditions.

2. Redistributions in binary form (compiled executables and libraries)
must reproduce the above copyright notice, definition, disclaimer,
and this list of conditions in documentation and/or other materials
provided with the distribution. The sole exception to this condition
is redistribution of a standard UnZipSFX binary (including SFXWiz) as
part of a self-extracting archive; that is permitted without inclusion
of this license, as long as the normal SFX banner has not been removed
from the binary or disabled.

3. Altered versions--including, but not limited to, ports to new operating
systems, existing ports with new graphical interfaces, versions with
modified or added functionality, and dynamic, shared, or static library
versions not from Info-ZIP--must be plainly marked as such and must not
be misrepresented as being the original source or, if binaries,
compiled from the original source. Such altered versions also must not
be misrepresented as being Info-ZIP releases--including, but not
limited to, labeling of the altered versions with the names "Info-ZIP"
(or any variation thereof, including, but not limited to, different
capitalizations), "Pocket UnZip," "WiZ" or "MacZip" without the
explicit permission of Info-ZIP. Such altered versions are further
prohibited from misrepresentative use of the Zip-Bugs or Info-ZIP
e-mail addresses or the Info-ZIP URL(s), such as to imply Info-ZIP
will provide support for the altered versions.

4. Info-ZIP retains the right to use the names "Info-ZIP," "Zip," "UnZip,"
"UnZipSFX," "WiZ," "Pocket UnZip," "Pocket Zip," and "MacZip" for its
own source and binary releases.
Binary file added utils/unzip.exe
Binary file not shown.

0 comments on commit 331ca2c

Please sign in to comment.