2 # -*- coding: utf-8 -*-
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the Revised BSD License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 Revised BSD License for more details.
13 Copyright 2018-2024 Cool Dude 2k - http://idb.berlios.de/
14 Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
15 Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
17 $FileInfo: catfile.py - Last Update: 2/11/2024 Ver. 0.0.2 RC 1 - Author: cooldude2k $
20 from __future__
import absolute_import
, division
, print_function
, unicode_literals
;
21 import os
, sys
, logging
, argparse
, pycatfile
;
22 from io
import open as open;
27 from cStringIO
import StringIO
as BytesIO
;
33 from StringIO
import StringIO
as BytesIO
;
39 from io
import BytesIO
;
44 __project__
= pycatfile
.__project
__;
45 __program_name__
= pycatfile
.__program
_name
__;
46 __project_url__
= pycatfile
.__project
_url
__;
47 __version_info__
= pycatfile
.__version
_info
__;
48 __version_date_info__
= pycatfile
.__version
_date
_info
__;
49 __version_date__
= pycatfile
.__version
_date
__;
50 __version_date_plusrc__
= pycatfile
.__version
_date
_plusrc
__
51 __version__
= pycatfile
.__version
__;
52 __version_date_plusrc__
= pycatfile
.__version
_date
_plusrc
__;
53 __cat_header_ver__
= pycatfile
.__cat
_header
_ver
__;
55 argparser
= argparse
.ArgumentParser(description
="Manipulating concatenate files", conflict_handler
="resolve", add_help
=True);
56 argparser
.add_argument("-V", "--version", action
="version", version
=__program_name__
+ " " + __version__
);
57 argparser
.add_argument("-i", "-f", "--input", help="files to concatenate or concatenate file extract", required
=True);
58 argparser
.add_argument("-d", "-v", "--verbose", action
="store_true", help="print various debugging information");
59 argparser
.add_argument("-c", "--create", action
="store_true", help="concatenate files only");
60 argparser
.add_argument("-checksum", "--checksum", default
="crc32", help="checksum type to use default is crc32");
61 argparser
.add_argument("-e", "-x", "--extract", action
="store_true", help="extract files only");
62 argparser
.add_argument("-l", "-t", "--list", action
="store_true", help="list files only");
63 argparser
.add_argument("-r", "--repack", action
="store_true", help="reconcatenate files only fixing checksum errors");
64 argparser
.add_argument("-o", "--output", default
=None, help="extract concatenate files to or concatenate output name");
65 argparser
.add_argument("-compression", "--compression", default
="auto", help="concatenate files with compression");
66 argparser
.add_argument("-level", "--level", default
=None, help="concatenate files with compression level");
67 argparser
.add_argument("-t", "--converttar", action
="store_true", help="convert tar file to catfile");
68 argparser
.add_argument("-z", "--convertzip", action
="store_true", help="convert tar file to catfile");
69 argparser
.add_argument("-T", "--text", action
="store_true", help="read file locations from text file");
70 getargs
= argparser
.parse_args();
72 should_extract
= False;
75 should_convert_tar
= False;
76 should_convert_zip
= False;
77 if(not getargs
.extract
and getargs
.create
and not getargs
.list):
79 should_extract
= False;
81 if(getargs
.extract
and not getargs
.create
and not getargs
.list):
82 should_create
= False;
83 should_extract
= True;
85 if(getargs
.extract
and getargs
.create
and not getargs
.list):
87 should_extract
= False;
89 if(not getargs
.extract
and not getargs
.create
and not getargs
.list):
91 should_extract
= False;
93 if(not getargs
.extract
and getargs
.create
and getargs
.list):
95 should_extract
= False;
97 if(getargs
.extract
and not getargs
.create
and getargs
.list):
98 should_create
= False;
99 should_extract
= True;
101 if(getargs
.extract
and getargs
.create
and getargs
.list):
102 should_create
= True;
103 should_extract
= False;
105 if(not getargs
.extract
and not getargs
.create
and getargs
.list):
106 should_create
= False;
107 should_extract
= False;
109 should_repack
= False;
110 if(should_create
and getargs
.repack
):
111 should_repack
= True;
112 if(getargs
.converttar
):
113 should_convert_tar
= True;
114 should_convert_zip
= False;
115 if(getargs
.convertzip
and not should_convert_tar
):
116 should_convert_zip
= True;
117 should_convert_tar
= False;
119 logging
.basicConfig(format
="%(message)s", stream
=sys
.stdout
, level
=logging
.DEBUG
);
120 if(should_create
and not should_extract
and not should_list
and not should_repack
):
121 if(should_convert_tar
):
122 pycatfile
.PackCatFileFromTarFile(getargs
.input, getargs
.output
, getargs
.compression
, getargs
.level
, getargs
.checksum
, getargs
.verbose
, False);
123 elif(should_convert_zip
and not should_convert_tar
):
124 pycatfile
.PackCatFileFromZipFile(getargs
.input, getargs
.output
, getargs
.compression
, getargs
.level
, getargs
.checksum
, getargs
.verbose
, False);
126 pycatfile
.PackCatFile(getargs
.input, getargs
.output
, getargs
.text
, getargs
.compression
, getargs
.level
, False, getargs
.checksum
, getargs
.verbose
, False);
127 if(should_create
and not should_extract
and not should_list
and should_repack
):
128 pycatfile
.RePackCatFile(getargs
.input, getargs
.output
, 0, 0, getargs
.compression
, getargs
.level
, False, getargs
.checksum
, False, getargs
.verbose
, False);
129 if(not should_create
and should_extract
and not should_list
):
130 pycatfile
.UnPackCatFile(getargs
.input, getargs
.output
, False, False, getargs
.verbose
, False);
131 if(not should_create
and not should_extract
and should_list
):
132 if(should_convert_tar
):
133 pycatfile
.TarFileListFiles(getargs
.input, getargs
.verbose
, False);
134 elif(should_convert_zip
and not should_convert_tar
):
135 pycatfile
.ZipFileListFiles(getargs
.input, getargs
.verbose
, False);
137 pycatfile
.CatFileListFiles(getargs
.input, 0, 0, False, getargs
.verbose
, False);