@ -56,93 +56,87 @@ int wmain(int argc, wchar_t *wargv[]) {
char * * argv = converter . get ( ) ;
char * * argv = converter . get ( ) ;
boost : : filesystem : : path : : imbue ( boost : : locale : : generator ( ) . generate ( " " ) ) ;
boost : : filesystem : : path : : imbue ( boost : : locale : : generator ( ) . generate ( " " ) ) ;
# endif
# endif
bpo : : options_description desc ( " Syntax: mwiniimporter <options> inifile configfile \n Allowed options " ) ;
bpo : : positional_options_description p_desc ;
desc . add_options ( )
( " help,h " , " produce help message " )
( " verbose,v " , " verbose output " )
( " ini,i " , bpo : : value < std : : string > ( ) , " morrowind.ini file " )
( " cfg,c " , bpo : : value < std : : string > ( ) , " openmw.cfg file " )
( " output,o " , bpo : : value < std : : string > ( ) - > default_value ( " " ) , " openmw.cfg file " )
( " game-files,g " , " import esm and esp files " )
( " no-archives,A " , " disable bsa archives import " )
( " encoding,e " , bpo : : value < std : : string > ( ) - > default_value ( " win1252 " ) ,
" Character encoding used in OpenMW game messages: \n "
" \n \t win1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages \n "
" \n \t win1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages \n "
" \n \t win1252 - Western European (Latin) alphabet, used by default " )
;
p_desc . add ( " ini " , 1 ) . add ( " cfg " , 1 ) ;
bpo : : variables_map vm ;
try
try
{
{
bpo : : options_description desc ( " Syntax: mwiniimporter <options> inifile configfile \n Allowed options " ) ;
bpo : : positional_options_description p_desc ;
desc . add_options ( )
( " help,h " , " produce help message " )
( " verbose,v " , " verbose output " )
( " ini,i " , bpo : : value < std : : string > ( ) , " morrowind.ini file " )
( " cfg,c " , bpo : : value < std : : string > ( ) , " openmw.cfg file " )
( " output,o " , bpo : : value < std : : string > ( ) - > default_value ( " " ) , " openmw.cfg file " )
( " game-files,g " , " import esm and esp files " )
( " no-archives,A " , " disable bsa archives import " )
( " encoding,e " , bpo : : value < std : : string > ( ) - > default_value ( " win1252 " ) ,
" Character encoding used in OpenMW game messages: \n "
" \n \t win1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages \n "
" \n \t win1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages \n "
" \n \t win1252 - Western European (Latin) alphabet, used by default " )
;
p_desc . add ( " ini " , 1 ) . add ( " cfg " , 1 ) ;
bpo : : variables_map vm ;
bpo : : parsed_options parsed = bpo : : command_line_parser ( argc , argv )
bpo : : parsed_options parsed = bpo : : command_line_parser ( argc , argv )
. options ( desc )
. options ( desc )
. positional ( p_desc )
. positional ( p_desc )
. run ( ) ;
. run ( ) ;
bpo : : store ( parsed , vm ) ;
bpo : : store ( parsed , vm ) ;
}
catch ( boost : : program_options : : unknown_option & x )
{
std : : cerr < < " ERROR: " < < x . what ( ) < < std : : endl ;
return false ;
}
catch ( boost : : program_options : : invalid_command_line_syntax & x )
{
std : : cerr < < " ERROR: " < < x . what ( ) < < std : : endl ;
return false ;
}
if ( vm . count ( " help " ) | | ! vm . count ( " ini " ) | | ! vm . count ( " cfg " ) ) {
std : : cout < < desc ;
return 0 ;
}
bpo : : notify ( vm ) ;
if ( vm . count ( " help " ) | | ! vm . count ( " ini " ) | | ! vm . count ( " cfg " ) ) {
std : : cout < < desc ;
return 0 ;
}
std : : string iniFile = vm [ " ini " ] . as < std : : string > ( ) ;
bpo : : notify ( vm ) ;
std : : string cfgFile = vm [ " cfg " ] . as < std : : string > ( ) ;
// if no output is given, write back to cfg file
std : : string iniFile = vm [ " ini " ] . as < std : : string > ( ) ;
std : : string outputFile ( vm [ " output " ] . as < std : : string > ( ) ) ;
std : : string cfgFile = vm [ " cfg " ] . as < std : : string > ( ) ;
if ( vm [ " output " ] . defaulted ( ) ) {
outputFile = vm [ " cfg " ] . as < std : : string > ( ) ;
}
if ( ! boost : : filesystem : : exists ( iniFile ) ) {
// if no output is given, write back to cfg file
std : : cerr < < " ini file does not exist " < < std : : endl ;
std : : string outputFile ( vm [ " output " ] . as < std : : string > ( ) ) ;
return - 3 ;
if ( vm [ " output " ] . defaulted ( ) ) {
}
outputFile = vm [ " cfg " ] . as < std : : string > ( ) ;
if ( ! boost : : filesystem : : exists ( cfgFile ) )
}
std : : cerr < < " cfg file does not exist " < < std : : endl ;
MwIniImporter importer ;
if ( ! boost : : filesystem : : exists ( iniFile ) ) {
importer . setVerbose ( vm . count ( " verbose " ) ) ;
std : : cerr < < " ini file does not exist " < < std : : endl ;
return - 3 ;
}
if ( ! boost : : filesystem : : exists ( cfgFile ) )
std : : cerr < < " cfg file does not exist " < < std : : endl ;
// Font encoding settings
MwIniImporter importer ;
std : : string encoding ( vm [ " encoding " ] . as < std : : string > ( ) ) ;
importer . setVerbose ( vm . count ( " verbose " ) ) ;
importer . setInputEncoding ( ToUTF8 : : calculateEncoding ( encoding ) ) ;
MwIniImporter : : multistrmap ini = importer . loadIniFile ( iniFile ) ;
// Font encoding settings
MwIniImporter : : multistrmap cfg = importer . loadCfgFile ( cfgFile ) ;
std : : string encoding ( vm [ " encoding " ] . as < std : : string > ( ) ) ;
importer . setInputEncoding ( ToUTF8 : : calculateEncoding ( encoding ) ) ;
importer . merge ( cfg , ini ) ;
MwIniImporter : : multistrmap ini = importer . loadIniFile ( iniFile ) ;
importer . mergeFallback ( cfg , ini ) ;
MwIniImporter : : multistrmap cfg = importer . loadCfgFile ( cfgFile ) ;
if ( vm . count ( " game-files " ) ) {
importer . merge ( cfg , ini ) ;
importer . importGameFiles ( cfg , ini ) ;
importer . mergeFallback ( cfg , ini ) ;
}
if ( ! vm . count ( " no-archiv es" ) ) {
if ( vm . count ( " game-fil es" ) ) {
importer . importArchiv es( cfg , ini ) ;
importer . importGameFil es( cfg , ini ) ;
}
}
std : : cout < < " write to: " < < outputFile < < std : : endl ;
if ( ! vm . count ( " no-archives " ) ) {
bfs : : ofstream file ( ( bfs : : path ( outputFile ) ) ) ;
importer . importArchives ( cfg , ini ) ;
importer . writeToFile ( file , cfg ) ;
}
std : : cout < < " write to: " < < outputFile < < std : : endl ;
bfs : : ofstream file ( ( bfs : : path ( outputFile ) ) ) ;
importer . writeToFile ( file , cfg ) ;
}
catch ( std : : exception & e )
{
std : : cerr < < " ERROR: " < < e . what ( ) < < std : : endl ;
}
return 0 ;
return 0 ;
}
}