42 |
|
using namespace boost::filesystem; |
43 |
|
using namespace std; |
44 |
|
|
45 |
+ |
string strInstallCfg = "../GameDataFolder/Install.cfg"; |
46 |
|
|
47 |
|
|
48 |
|
int main(void) |
306 |
|
|
307 |
|
int installPackages(void) |
308 |
|
{ |
309 |
+ |
bool installed_something = 0; |
310 |
|
int err = 0; |
311 |
|
ModPackage package; |
312 |
|
vector<string> installed_packages; |
357 |
|
cout << "\nInstalling...\n\n"; |
358 |
|
if (package_iter->hasOnis || (package_iter->hasDeltas /*(*package_iter).isUnpacked */ )) |
359 |
|
{ |
360 |
+ |
installed_something = 1; |
361 |
|
installedMods.push_back(package_iter->modStringName); |
362 |
|
system(strPauseCmd); |
363 |
|
} |
366 |
|
} |
367 |
|
if (index == 1) |
368 |
|
{ |
369 |
< |
cout << "Error: All packages are already installed\n"; |
369 |
> |
cout << "Warning: All packages are already installed\n"; |
370 |
> |
//would you like to recombine your data? |
371 |
|
return 0; |
372 |
|
} |
373 |
< |
|
373 |
> |
if (installed_something == 0) |
374 |
> |
{ |
375 |
> |
cout << "Warning: You didn't install anything!\n"; |
376 |
> |
//would you like to recombine your data? |
377 |
> |
return 0; |
378 |
> |
} |
379 |
> |
|
380 |
|
sort(installedMods.begin(), installedMods.end()); |
381 |
|
//system(Onisplit.c_str()); |
382 |
|
recompileAll(installedMods); |
387 |
|
|
388 |
|
int uninstallPackages(void) |
389 |
|
{ |
390 |
< |
cout << "\nThis feature not yet implemented.\n\n"; |
390 |
> |
int err = 0; |
391 |
> |
ModPackage package; |
392 |
> |
vector<string> installed_packages; |
393 |
> |
vector<ModPackage> packages; |
394 |
> |
vector<ModPackage>::iterator iter; |
395 |
> |
vector<string> installString; |
396 |
|
|
397 |
< |
return 0; |
397 |
> |
iter = packages.begin(); |
398 |
> |
packages = getPackages(); |
399 |
> |
|
400 |
> |
|
401 |
> |
cout << "Detecting installed packages...\n"; |
402 |
> |
|
403 |
> |
vector<string> installedMods = getInstallString(); |
404 |
> |
|
405 |
> |
if (packages.empty()) |
406 |
> |
{ |
407 |
> |
cout << "Error: You have no packages!\n"; |
408 |
> |
return 0; |
409 |
> |
} |
410 |
> |
|
411 |
> |
int index = 0; |
412 |
> |
int uninstalled_something = 0; |
413 |
> |
char choice = '0'; |
414 |
> |
|
415 |
> |
for (vector<ModPackage>::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter) |
416 |
> |
{ |
417 |
> |
if (binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName)) |
418 |
> |
{ //package_iter->isInstalled :< I forgot about this... |
419 |
> |
//cout << index << " "; |
420 |
> |
system(strClsCmd); |
421 |
> |
cout << (*package_iter).name << "\n"; |
422 |
> |
for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << '-'; |
423 |
> |
cout << "\n" |
424 |
> |
<< (*package_iter).readme << "\n\n" |
425 |
> |
<< "Please enter a number choice\n" |
426 |
> |
<< " 1. Uninstall\n" |
427 |
> |
<< " 2. Don't Uninstall\n" |
428 |
> |
<< ""; |
429 |
> |
|
430 |
> |
choice = 0; |
431 |
> |
|
432 |
> |
do |
433 |
> |
{ |
434 |
> |
choice = cin.get(); |
435 |
> |
cin.ignore(1280, '\n'); |
436 |
> |
} while(choice == 0); |
437 |
> |
|
438 |
> |
if (choice == '1') |
439 |
> |
{ |
440 |
> |
cout << "\nUninstalling...\n\n"; |
441 |
> |
installedMods.erase( installedMods.begin() + (index) ); |
442 |
> |
system(strPauseCmd); |
443 |
> |
uninstalled_something = 1; |
444 |
> |
|
445 |
> |
} |
446 |
> |
else { |
447 |
> |
index++; |
448 |
> |
} |
449 |
> |
} |
450 |
> |
} |
451 |
> |
if ( uninstalled_something == 0 ) |
452 |
> |
{ |
453 |
> |
if (index == 0) //bad practice, I need to implement a second vector or something. Meh. |
454 |
> |
{ |
455 |
> |
cout << "\nWarning: You have no installed packages!"; |
456 |
> |
} |
457 |
> |
else |
458 |
> |
{ |
459 |
> |
cout << "\nWarning: You didn't uninstall anything!"; |
460 |
> |
} |
461 |
> |
//would you like to recombine your data? |
462 |
> |
return 0; |
463 |
> |
|
464 |
> |
} |
465 |
> |
sort(installedMods.begin(), installedMods.end()); |
466 |
> |
//system(Onisplit.c_str()); |
467 |
> |
recompileAll(installedMods); |
468 |
> |
system(strPauseCmd); |
469 |
> |
|
470 |
> |
return err; |
471 |
|
} |
472 |
|
|
473 |
|
int listInstalledPackages(void) |
639 |
|
path vanilla_dir = "./packages/VanillaDats/"; |
640 |
|
string importCommand = ""; |
641 |
|
|
642 |
< |
directory_iterator end_iter_gdf; |
555 |
< |
for ( directory_iterator dir_itr_gdf( "../GameDataFolder" ); |
556 |
< |
dir_itr_gdf != end_iter_gdf; |
557 |
< |
++dir_itr_gdf ) |
558 |
< |
{ |
559 |
< |
//cout << dir_itr_gdf->path().extension() << "\n"; |
560 |
< |
if ( dir_itr_gdf->path().extension() == ".dat" || dir_itr_gdf->path().extension() == ".raw" || dir_itr_gdf->path().extension() == ".sep" ) { |
561 |
< |
remove( dir_itr_gdf->path() ); |
562 |
< |
} |
563 |
< |
|
564 |
< |
} |
642 |
> |
clearOldDats(); |
643 |
|
|
644 |
|
if(splitInstances == SPLIT){ |
645 |
|
recursive_directory_iterator end_iter; |
697 |
|
} |
698 |
|
} |
699 |
|
} |
700 |
+ |
writeInstalledMods(installedMods); |
701 |
+ |
} |
702 |
+ |
|
703 |
+ |
void writeInstalledMods(vector<string> installedMods) |
704 |
+ |
{ |
705 |
+ |
|
706 |
+ |
if ( exists( strInstallCfg ) ) |
707 |
+ |
{ |
708 |
+ |
remove( strInstallCfg ); |
709 |
+ |
} |
710 |
+ |
|
711 |
+ |
ofstream file(strInstallCfg.c_str()); |
712 |
+ |
|
713 |
+ |
vector<string>list = installedMods; |
714 |
+ |
vector<string>::iterator begin_iter = list.begin(); |
715 |
+ |
vector<string>::iterator end_iter = list.end(); |
716 |
+ |
|
717 |
+ |
sort( list.begin(), list.end() ); |
718 |
+ |
|
719 |
+ |
for( ; begin_iter != end_iter; ++begin_iter) { |
720 |
+ |
file << *begin_iter << " "; |
721 |
+ |
} |
722 |
+ |
|
723 |
+ |
file.close(); |
724 |
+ |
file.clear(); |
725 |
+ |
|
726 |
|
} |
727 |
|
|
728 |
|
vector<string> getInstallString(void) |
729 |
|
{ |
730 |
|
system(strPauseCmd); |
731 |
|
vector<string> returnval; |
732 |
< |
string file_name = "../GameDataFolder/ImportList.cfg"; |
732 |
> |
|
733 |
|
string line; |
734 |
|
fstream file; |
735 |
|
|
736 |
< |
if (exists(file_name)) |
736 |
> |
if (exists(strInstallCfg )) |
737 |
|
{ |
738 |
< |
file.open(file_name.c_str()); |
738 |
> |
file.open(strInstallCfg.c_str()); |
739 |
|
getline(file, line); |
740 |
|
tokenize(line, returnval); |
741 |
|
file.close(); |
764 |
|
// Find next "non-delimiter" |
765 |
|
pos = str.find_first_of(delimiters, lastPos); |
766 |
|
} |
767 |
< |
} |
767 |
> |
} |
768 |
> |
|
769 |
> |
void clearOldDats(void) { |
770 |
> |
directory_iterator end_iter_gdf; |
771 |
> |
for ( directory_iterator dir_itr_gdf( "../GameDataFolder" ); |
772 |
> |
dir_itr_gdf != end_iter_gdf; |
773 |
> |
++dir_itr_gdf ) |
774 |
> |
{ |
775 |
> |
//cout << dir_itr_gdf->path().extension() << "\n"; |
776 |
> |
if ( dir_itr_gdf->path().extension() == ".dat" || dir_itr_gdf->path().extension() == ".raw" || dir_itr_gdf->path().extension() == ".sep" ) { |
777 |
> |
remove( dir_itr_gdf->path() ); |
778 |
> |
} |
779 |
> |
|
780 |
> |
} |
781 |
> |
|
782 |
> |
} |