// Dat2ProcessMegamod.cpp : main project file.
#include "StdAfx.h"
#include <time.h>
#include <iostream>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream> 
using namespace std;

string RemoveGarbage(string InputFileName) {
	InputFileName.erase(InputFileName.begin(),InputFileName.end()-12);
   return InputFileName;
}

void wait ( int seconds )
{
  clock_t endwait;
  endwait = clock () + seconds * CLOCKS_PER_SEC ;
  while (clock() < endwait) {}
}

int main() {
	 string line;
    ifstream myfile;
    myfile.open ("proto\\Dat Replace.txt");

    if(!myfile.is_open()) {
		 cout << "Dat Replace.txt not found." << endl;
		 cin.get();
	    exit(1);
	 }
    while (! myfile.eof() )
    {
		std::stringstream one;
	   std::string ones;
		std::stringstream two;
	   std::string twos;
		std::stringstream three;
	   std::string threes;
      getline (myfile,line);
		if (line != "") {
	      cout << "                                                        " << endl;
	      cout << "                                                        " << endl;
	      cout << "Deleting Base Party Member Proto File " << RemoveGarbage(line) << endl;
	      wait ( 2 );
         one << "START proto\\dat2 d master proto\\CRITTERS\\" << line;
         ones = one.str(); 
		   system(ones.c_str());
	      cout << "                                                        " << endl;
	      cout << "                                                        " << endl;
	      cout << "Adding Base Party Member Proto File " << RemoveGarbage(line) << endl;
		   wait ( 2 ); 
         two << "START proto\\dat2 a master proto\\CRITTERS\\" << line;
	 	   twos = two.str();
		   system(twos.c_str());
	      cout << "                                                        " << endl;
	      cout << "                                                        " << endl;
	      cout << "Deleting Base Party Member Proto File " << RemoveGarbage(line) << " from dato\\proto\\critters" << endl;
		   wait ( 2 ); 
         three << "del /q /f data\\proto\\critters\\" << line; 
         threes = three.str(); 
		   system(threes.c_str());
      }
   }
	myfile.close();
	system("attrib +r data\\proto\\critters\\*.pro");
	system("attrib +r data\\proto\\items\\*.pro");
 	cout << "                                                        " << endl;
	cout << "                                                        " << endl;
	cout << "Setting Item and Critter Pro Files To Read Only." << endl;
	wait ( 2 );
} 
