@@ -31,6 +31,7 @@ THE SOFTWARE.
3131
3232Convert::Convert () noexcept
3333: m_options()
34+ , m_initialized(true )
3435{
3536}
3637
@@ -48,13 +49,14 @@ Convert::~Convert() noexcept
4849
4950bool Convert::init (int argc, char *argv[]) noexcept
5051{
51- return m_options.init (argc, argv);
52+ return (m_initialized = m_options.init (argc, argv) );
5253}
5354
5455
5556bool Convert::execute () noexcept
5657{
5758 // checking state
59+ if (!isInitialized ()) return false ;
5860 if (getOptions ().getInputCount () == 0 ) return false ;
5961
6062 // Special case: show information of input files only
@@ -75,18 +77,18 @@ bool Convert::execute() noexcept
7577 bool retVal = true ;
7678 for (int i = 0 ; i < getOptions ().getInputCount (); i++) {
7779 if (!getOptions ().isSilent () && getOptions ().getInputCount () > 1 ) {
78- std::printf (" Processing file %d of %d\n " , i+1 , getOptions ().getInputCount ());
80+ std::printf (" \n Processing file %d of %d\n " , i+1 , getOptions ().getInputCount ());
7981 }
8082 const std::string &inputFile = getOptions ().getInput (i);
8183 std::string outputFile;
8284 if (!inputFile.empty ()) {
83- switch (Options::GetFileType (inputFile)) {
85+ switch (Options::GetFileType (inputFile, getOptions (). assumeTis () )) {
8486 case FileType::TIS:
8587 // generating output filename
86- if (! getOptions ().isOutput ()) {
87- outputFile = Options::SetFileExt (inputFile, FileType::TBC );
88+ if (getOptions ().isOutFile ()) {
89+ outputFile = getOptions (). getOutPath () + getOptions (). getOutFile ( );
8890 } else {
89- outputFile = getOptions ().getOutput ( );
91+ outputFile = getOptions ().getOutPath () + Options::SetFileExt (inputFile, FileType::TBC );
9092 }
9193 if (outputFile.empty ()) {
9294 retVal = false ;
@@ -101,7 +103,6 @@ bool Convert::execute() noexcept
101103 if (!getOptions ().isSilent ()) {
102104 std::printf (" Converting TIS -> TBC\n " );
103105 std::printf (" Input: \" %s\" , output: \" %s\"\n " , inputFile.c_str (), outputFile.c_str ());
104- std::printf (" Converting...\n " );
105106 }
106107 if (!gfx.tisToTBC (inputFile, outputFile)) {
107108 retVal = false ;
@@ -113,10 +114,10 @@ bool Convert::execute() noexcept
113114 break ;
114115 case FileType::MOS:
115116 // generating output filename
116- if (! getOptions ().isOutput ()) {
117- outputFile = Options::SetFileExt (inputFile, FileType::MBC );
117+ if (getOptions ().isOutFile ()) {
118+ outputFile = getOptions (). getOutPath () + getOptions (). getOutFile ( );
118119 } else {
119- outputFile = getOptions ().getOutput ( );
120+ outputFile = getOptions ().getOutPath () + Options::SetFileExt (inputFile, FileType::MBC );
120121 }
121122 if (outputFile.empty ()) {
122123 retVal = false ;
@@ -131,7 +132,6 @@ bool Convert::execute() noexcept
131132 if (!getOptions ().isSilent ()) {
132133 std::printf (" Converting MOS -> MBC\n " );
133134 std::printf (" Input: \" %s\" , output: \" %s\"\n " , inputFile.c_str (), outputFile.c_str ());
134- std::printf (" Converting...\n " );
135135 }
136136 if (!gfx.mosToMBC (inputFile, outputFile)) {
137137 retVal = false ;
@@ -143,10 +143,10 @@ bool Convert::execute() noexcept
143143 break ;
144144 case FileType::TBC:
145145 // generating output filename
146- if (! getOptions ().isOutput ()) {
147- outputFile = Options::SetFileExt (inputFile, FileType::TIS );
146+ if (getOptions ().isOutFile ()) {
147+ outputFile = getOptions (). getOutPath () + getOptions (). getOutFile ( );
148148 } else {
149- outputFile = getOptions ().getOutput ( );
149+ outputFile = getOptions ().getOutPath () + Options::SetFileExt (inputFile, FileType::TIS );
150150 }
151151 if (outputFile.empty ()) {
152152 retVal = false ;
@@ -161,7 +161,6 @@ bool Convert::execute() noexcept
161161 if (!getOptions ().isSilent ()) {
162162 std::printf (" Converting TBC -> TIS\n " );
163163 std::printf (" Input: \" %s\" , output: \" %s\"\n " , inputFile.c_str (), outputFile.c_str ());
164- std::printf (" Converting...\n " );
165164 }
166165 if (!gfx.tbcToTIS (inputFile, outputFile)) {
167166 retVal = false ;
@@ -173,10 +172,10 @@ bool Convert::execute() noexcept
173172 break ;
174173 case FileType::MBC:
175174 // generating output filename
176- if (! getOptions ().isOutput ()) {
177- outputFile = Options::SetFileExt (inputFile, FileType::MOS );
175+ if (getOptions ().isOutFile ()) {
176+ outputFile = getOptions (). getOutPath () + getOptions (). getOutFile ( );
178177 } else {
179- outputFile = getOptions ().getOutput ( );
178+ outputFile = getOptions ().getOutPath () + Options::SetFileExt (inputFile, FileType::MOS );
180179 }
181180 if (outputFile.empty ()) {
182181 retVal = false ;
@@ -191,7 +190,6 @@ bool Convert::execute() noexcept
191190 if (!getOptions ().isSilent ()) {
192191 std::printf (" Converting MBC -> MOS\n " );
193192 std::printf (" Input: \" %s\" , output: \" %s\"\n " , inputFile.c_str (), outputFile.c_str ());
194- std::printf (" Converting...\n " );
195193 }
196194 if (!gfx.mbcToMOS (inputFile, outputFile)) {
197195 retVal = false ;
@@ -261,8 +259,7 @@ bool Convert::showInfo(const std::string &fileName) noexcept
261259 isMosc = true ;
262260
263261 // getting MOSC file size
264- f.seek (0 , SEEK_END);
265- moscSize = f.tell ();
262+ moscSize = f.getsize ();
266263 if (moscSize <= 12 ) {
267264 std::printf (" Invalid MOSC size\n " );
268265 return false ;
@@ -294,8 +291,7 @@ bool Convert::showInfo(const std::string &fileName) noexcept
294291 }
295292 } else {
296293 // reading MOS header into memory
297- f.seek (0 , SEEK_END);
298- mosSize = f.tell ();
294+ mosSize = f.getsize ();
299295 if (mosSize < 24 ) {
300296 std::printf (" MOS size too small\n " );
301297 return false ;
0 commit comments