// ProcessDat2.cpp : Defines the entry point for the console application.
//

#include "StdAfx.h"
#include <time.h>
#include <iostream>
#include <string>
#include <fstream>

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 _tmain(int argc, _TCHAR* argv[])
{
	 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);
	 }
	size_t loc;
    while (! myfile.eof() )
    {
      getline (myfile,line);
		std::string folder_files = "del /q /f data\\proto\\critters\\";
	   std::string del = "START proto\\dat2 d master";
	   std::string add = "START proto\\dat2 a master";
		if (line != "") {
         del.append(" proto\\CRITTERS\\");
			del.append(RemoveGarbage(line));
			while ((loc=del.find("//"))!=string::npos) {
				del.erase(loc,1);
			}
			cout << "Deleting Base Party Member Proto File " << RemoveGarbage(line) << " from Master.Dat." << endl;
			system(del.c_str());
			wait ( 1 ); 
			std::string del = "";
			add.append(" proto\\CRITTERS\\");
			add.append(RemoveGarbage(line));
			while ((loc=add.find("//"))!=string::npos) {
				add.erase(loc,1);
			}
			cout << "Adding Base Party Member Proto File " << RemoveGarbage(line) << " to Master.Dat." << endl;
			system(add.c_str());
			wait ( 1 ); 




























			std::string add = "";
	      cout << "                                                        " << endl;
	      cout << "                                                        " << endl;
	      cout << "Deleting Base Party Member Proto File " << RemoveGarbage(line) << " from dato\\proto\\critters" << endl;
         folder_files.append(RemoveGarbage(line)); 
			while ((loc=folder_files.find("//"))!=string::npos) {
				folder_files.erase(loc,1);
			}
		   system(folder_files.c_str());
			wait ( 1 );
			std::string folder_files = "";
      }
   }
	myfile.close();
	cout << "                                                        " << endl;
	cout << "                                                        " << endl;
	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 );
} 

