Skip to content

Commit

Permalink
+ list_file
Browse files Browse the repository at this point in the history
  • Loading branch information
kanasimi committed Jul 7, 2024
1 parent 16ccb71 commit 11a12ad
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
53 changes: 37 additions & 16 deletions application/storage/EPUB.js
Original file line number Diff line number Diff line change
Expand Up @@ -2646,17 +2646,32 @@ function module_code(library_namespace) {
// On computers running Microsoft Windows XP or later, the maximum
// length of the string that you can use at the command prompt is 8191
// characters.
if (Array.isArray(file_list) && file_list.join('" "').length > 7800) {
library_namespace.warn([ archive_to_ZIP.name + ': ', {
// gettext_config:{"id":"the-file-list-is-too-long-so-it-is-changed-to-compress-the-entire-directory"}
T : '檔案列表過長,改成壓縮整個目錄。'
} ]);
// 當 epub 電子書非本工具產生時,可能有不同的目錄,必須重新讀取。
file_list = library_namespace.read_directory(this.path.root)
// archive all directory without mimetype
.filter(function(fso_name) {
return fso_name !== mimetype_filename;
});
var list_file_name;
if (false && Array.isArray(file_list)
&& file_list.join('" "').length > 7800) {
list_file_name = '!list_file.tmp.lst';
library_namespace.write_file(this.path.root + list_file_name,
file_list.join('\n'));
file_list = [];

if (false) {
library_namespace.warn([ archive_to_ZIP.name + ': ', {
// gettext_config:{"id":"the-file-list-is-too-long-so-it-is-changed-to-compress-the-entire-directory"}
T : '檔案列表過長,改成壓縮整個目錄。'
} ]);
// 當 epub 電子書非本工具產生時,可能有不同的目錄,必須重新讀取。
file_list = library_namespace.read_directory(this.path.root)
// archive all directory without mimetype
.filter(function(fso_name) {
return fso_name !== mimetype_filename;
});
if (file_list.join('" "').length > 7800) {
library_namespace.error([
archive_to_ZIP.name + ': ',
'檔案列表仍然過長,總長' + file_list.join('" "').length
+ '位元組。' ]);
}
}

} else if (!file_list) {
file_list = [ container_directory_name,
Expand All @@ -2669,17 +2684,23 @@ function module_code(library_namespace) {
// 請注意: rename 必須先安裝 7-Zip **16.04 以上的版本**。
archive_file.rename([ mimetype_filename, mimetype_first_order_name ]);

// console.log([ this.path, file_list ]);
library_namespace.storage.archive.archive_under(this.path.root,
// archive others.
archive_file, {
var archive_options = {
// set MAX lavel
level : 9,
files : file_list,
recurse : true,
extra : (remove ? '-sdel ' : ''),
type : 'zip'
});
};

if (list_file_name) {
archive_options.list_file = list_file_name;
}

// console.log([ this.path, file_list ]);
library_namespace.storage.archive.archive_under(this.path.root,
// archive others.
archive_file, archive_options);

// recover mimetype
archive_file.rename([ mimetype_first_order_name, mimetype_filename ]);
Expand Down
39 changes: 38 additions & 1 deletion application/storage/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ function module_code(library_namespace) {
command.push(FSO_list);
}

// console.trace(command);
command = command.join(' ');
library_namespace.debug({
// gettext_config:{"id":"working-directory-$1"}
Expand Down Expand Up @@ -649,6 +650,10 @@ function module_code(library_namespace) {
extra : function(value) {
if (value)
return value;
},
list_file : function(value) {
if (value)
return add_fso_path_quote('-i@' + value);
}
},
zip : {
Expand Down Expand Up @@ -714,6 +719,10 @@ function module_code(library_namespace) {
= apply_switches_handler[program_type][switch_name]
//
.call(this, options[switch_name]);
} else if (false) {
library_namespace.warn(
//
'Switch unchanged [' + switch_name + ']');
}
}
}
Expand Down Expand Up @@ -1031,6 +1040,9 @@ function module_code(library_namespace) {
// type : 'zip',
files : options
};
} else {
// archive_options
options = library_namespace.setup_options(options);
}

// https://www.7-zip.org/faq.html
Expand All @@ -1052,8 +1064,33 @@ function module_code(library_namespace) {
var archive_file = is_Archive_file(archive_file_path) ? archive_file_path
: new Archive_file(archive_file_path, options),
//
files_to_archive = options && options.files || '.';
files_to_archive = options.files || '.', list_file_name, list_file_path;
if (Array.isArray(files_to_archive)
&& files_to_archive.join('" "').length > 7800) {
list_file_name = '!list_file.tmp.lst';
if (false) {
// Now under source_directory
list_file_path = library_namespace.append_path_separator(
source_directory, list_file_name);
}
list_file_path = list_file_name;
library_namespace.info([ archive_under.name + ': ', {
T : '檔案列表過長,寫入列表檔以壓縮 [' + list_file_path + ']。'
} ]);
library_namespace.write_file(list_file_path, files_to_archive
.join('\n'));
options.list_file = list_file_path;
files_to_archive = [];
delete options.files;
if (false) {
console.trace([ library_namespace.storage.working_directory(),
source_directory, options ]);
}
}
archive_file.update(files_to_archive, options);
if (list_file_name) {
library_namespace.remove_file(list_file_path);
}
// recover working directory.
library_namespace.storage.working_directory(original_working_directory);
return archive_file;
Expand Down

0 comments on commit 11a12ad

Please sign in to comment.