Skip to content

Commit

Permalink
Don't force mod to fail when processing invalid DLC archives
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Mar 12, 2018
1 parent 0df8754 commit 5aacaa0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 33 deletions.
1 change: 1 addition & 0 deletions DlcMerger/languages/english/setup.tra
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@

@400 = ~Merging DLC "%dlc_name%"...~
@401 = ~No DLC archives found. Installation cancelled.~
@402 = ~Failed to merge DLC archive "%dlc_name%" (%message%). Skipping...~
100 changes: 67 additions & 33 deletions DlcMerger/lib/dlcmerge.tph
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
INCLUDE ~%MOD_FOLDER%/lib/functions.tph~

DEFINE_ACTION_FUNCTION MERGE_DLC
INT_VAR
fail_on_error = 1
STR_VAR
dlc_res = ~sod-dlc~
path_temp = ~~
path_unzip = ~unzip~
RET
success // success status
message // error message on failure
BEGIN
OUTER_SET success = 0
OUTER_TEXT_SPRINT message ~~

OUTER_SET failed = 0

ACTION_IF (~%path_temp%~ STR_EQ ~~) BEGIN
OUTER_TEXT_SPRINT path_temp ~%MOD_FOLDER%/temp~
END
Expand All @@ -19,42 +29,66 @@ BEGIN
AT_NOW ret_val ~%unzip% -oqq "%dlc_filespec%" -x mod.key -d "%path_temp%"~
ACTION_IF (ret_val != 0) BEGIN
DELETE + ~%path_temp%~
FAIL @202 // Could not unpack DLC archive.
END
LAF COPY_RECURSIVE
INT_VAR
delete = 1 // delete file after copy operation
STR_VAR
source_dir = EVAL ~%path_temp%~
dest_dir = ~~
biff_folder = EVAL ~%dlc_res%~
ACTION_IF (fail_on_error) BEGIN
FAIL @202 // Could not unpack DLC archive.
END ELSE BEGIN
OUTER_SET failed = 1
OUTER_SPRINT message @202 // Could not unpack DLC archive.
END
END

PRINT @100 // Merging keys...
MKDIR ~%path_temp%~
AT_NOW ret_val ~%unzip% -oqq "%dlc_filespec%" mod.key -d "%path_temp%"~
ACTION_IF (ret_val != 0 || NOT FILE_EXISTS ~%path_temp%/mod.key~) BEGIN
DELETE + ~%path_temp%~
FAIL @200 // DLC archive is corrupt or incomplete.
END
LAF MERGE_KEYS
STR_VAR
chitin_key = ~chitin.key~
mod_key = EVAL ~%path_temp%/mod.key~
biff_folder = EVAL ~%dlc_res%~
RET
success
END
ACTION_IF (NOT success) BEGIN
DELETE + ~%path_temp%~
FAIL @201 // Unable to merge keys.
ACTION_IF (NOT failed) BEGIN
LAF COPY_RECURSIVE
INT_VAR
delete = 1 // delete file after copy operation
STR_VAR
source_dir = EVAL ~%path_temp%~
dest_dir = ~~
biff_folder = EVAL ~%dlc_res%~
END

PRINT @100 // Merging keys...
MKDIR ~%path_temp%~
AT_NOW ret_val ~%unzip% -oqq "%dlc_filespec%" mod.key -d "%path_temp%"~
ACTION_IF (ret_val != 0 || NOT FILE_EXISTS ~%path_temp%/mod.key~) BEGIN
DELETE + ~%path_temp%~
ACTION_IF (fail_on_error) BEGIN
FAIL @200 // DLC archive is corrupt or incomplete.
END ELSE BEGIN
OUTER_SET failed = 1
OUTER_SPRINT message @200 // DLC archive is corrupt or incomplete.
END
END

ACTION_IF (NOT failed) BEGIN
LAF MERGE_KEYS
STR_VAR
chitin_key = ~chitin.key~
mod_key = EVAL ~%path_temp%/mod.key~
biff_folder = EVAL ~%dlc_res%~
RET
merge_success = success
END
ACTION_IF (NOT merge_success) BEGIN
DELETE + ~%path_temp%~
ACTION_IF (fail_on_error) BEGIN
FAIL @201 // Unable to merge keys.
END ELSE BEGIN
OUTER_SET failed = 1
OUTER_SPRINT message @201 // Unable to merge keys.
END
END
END
END

DELETE + ~%path_temp%~
// TODO: MOVE currently fails if paths contain spaces
ACTION_IF (~%dlc_filespec%~ STRING_CONTAINS_REGEXP ~[ %TAB%]~ = 0) BEGIN
PRINT ~IMPORTANT: Please rename "%dlc_filespec%" to "%dlc_res%.disabled", so that it doesn't interfere with the merged DLC resources.~
END ELSE BEGIN
MOVE ~%dlc_filespec%~ ~%dlc_directory%/%dlc_res%.disabled~
ACTION_IF (NOT failed) BEGIN
DELETE + ~%path_temp%~
// TODO: MOVE currently fails if paths contain spaces
ACTION_IF (~%dlc_filespec%~ STRING_CONTAINS_REGEXP ~[ %TAB%]~ = 0) BEGIN
PRINT ~IMPORTANT: Please rename "%dlc_filespec%" to "%dlc_res%.disabled", so that it doesn't interfere with the merged DLC resources.~
END ELSE BEGIN
MOVE ~%dlc_filespec%~ ~%dlc_directory%/%dlc_res%.disabled~
END
OUTER_SET success = 1
END
END
8 changes: 8 additions & 0 deletions DlcMerger/setup-DlcMerger.tp2
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,18 @@ ACTION_FOR_EACH path IN ~%USER_DIRECTORY%~ ~.~ ~dlc~ ~workshop~ BEGIN
END
PRINT @400 // Merging DLC "%dlc_name%"...
LAF MERGE_DLC
INT_VAR
fail_on_error = 0
STR_VAR
dlc_res = EVAL ~%dlc_name%~
path_temp
path_unzip = EVAL ~%unzip%~
RET
success
message
END
ACTION_IF (NOT success) BEGIN
WARN @402 // Failed to merge DLC archive "%dlc_name%" (%message%). Skipping...
END
END
ACTION_CLEAR_ARRAY ~files~
Expand Down

0 comments on commit 5aacaa0

Please sign in to comment.