Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program for verifying GameFront OFP backup
- // 1. Check if files listed in MainList.txt really exist in the sub-directories
- // 2. Check if files listed in MainList.txt are also listed in _Info.txt
- // Headers:
- #include "stdafx.h" // VS
- #include <vector> // vectors
- #include <windows.h> // winapi
- #include <filesystem> // directory iterator
- // Namespaces:
- using namespace std;
- using namespace std::tr2::sys;
- // Global variables:
- ofstream logfile;
- // Functions:
- //-------------------------------------------------------------------------------
- // Open main list, extract titles & names and put them to vectors
- void ListToVector(string filename, vector<string>& titles, vector<string>& names)
- {
- // Open file
- fstream listfile;
- listfile.open(filename, ios::in);
- if (!listfile.is_open())
- return;
- // Copy text to a string
- string content((istreambuf_iterator<char>(listfile)), istreambuf_iterator<char>());
- // Parse
- size_t uploaded = content.find("Uploaded:");
- while (uploaded != string::npos)
- {
- // Line after "uploaded" contains title
- size_t TitleStart = content.find("\n", uploaded);
- size_t TitleEnd = content.find("\n", TitleStart+1);
- // Extract title
- string Title = content.substr(TitleStart+1, TitleEnd-TitleStart-1);
- // Two lines after title there is a filename
- size_t FileStart = content.find_first_not_of(" \t\f\v\n\r", TitleEnd);
- size_t FileEnd = content.find(" |", FileStart);
- // Extract filename
- string FileName = content.substr(FileStart, FileEnd-FileStart);
- // Copy extracted data to vectors
- titles.push_back(Title);
- names .push_back(FileName);
- // Find next occurence
- uploaded = content.find("Uploaded:", uploaded+1);
- };
- listfile.close();
- };
- //-------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------
- // Open info list, extract title and put it to a vector
- void InfoToVector(string filename, vector<string>& titles)
- {
- //logfile << "\tfile:" << filename << endl;
- // Open file
- fstream info;
- info.open(filename, ios::in);
- if (!info.is_open())
- return;
- // Variables for parsing
- string line; // holds current line
- bool nextIsTitle = true; // copy line to vector
- bool nextIsSeparator = false; // switch nextIsTitle
- // For each line
- while (getline(info, line))
- {
- //logfile << line << endl;
- // If it's a title
- if (nextIsTitle && !isspace(line[0]))
- {
- //logfile << line << endl;
- // Copy to vector
- titles.push_back(line);
- // Condition to quit particular file to prevent crashing
- if (filename.compare(".\\Modifications\\Add Ons\\Weapons\\_Info.txt") == 0 && line == "[PSOL] DesertEagle.zip")
- break;
- nextIsTitle = false;
- };
- // "Popularity" precedes separator
- if (line.compare(0, 11, "Popularity:") == 0)
- nextIsSeparator = true;
- // If it's a item separator
- if (nextIsSeparator && line.compare(0, 3, "===") == 0)
- nextIsSeparator = false,
- nextIsTitle = true;
- };
- info.close();
- };
- //-------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------
- // Log vector contents
- void VectorToLog(vector<string>& var)
- {
- for (vector<string>::iterator q = var.begin(); q != var.end(); q++)
- if (*q != "null")
- logfile << "\t" << *q << endl;
- };
- //-------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------
- // Our program
- int _tmain(int argc, _TCHAR* argv[])
- {
- // Start logging
- logfile.open("logfile.txt", ios::out | ios::trunc);
- // Create vectors
- vector<string> FileTitle; // for verifying files
- vector<string> FileName;
- vector<string> FileTitle2; // for verifying info lists
- vector<string> InfoTitle;
- // Fill vectors
- ListToVector("MainList.txt", FileTitle, FileName);
- // Find out if this is the "Operation Flashpoint" folder
- char buffer[MAX_PATH];
- GetModuleFileNameA(NULL, buffer, MAX_PATH);
- string exepath = string(buffer);
- // If it is then we need to remove files from the other games
- if (exepath.find("\\Operation Flashpoint\\") != string::npos)
- {
- // list of other directories
- vector<string> dirs
- {
- "Operation Flashpoint 2 Dragon Rising",
- "Operation Flashpoint Dragon Rising Red River",
- "Operation Flashpoint Elite",
- "Operation Flashpoint Red River",
- "Operation Flashpoint Resistance"
- };
- // temporary vectors
- vector<string> tmp_titles;
- vector<string> tmp_names;
- // iterate through the dir list
- for (vector<string>::iterator q = dirs.begin(); q != dirs.end(); q++)
- {
- tmp_titles.clear();
- tmp_names.clear();
- // Get lists from the other folders to a temporary vector
- string filename = "..\\" + *q + "\\MainList.txt";
- ListToVector(filename, tmp_titles, tmp_names);
- // for each entry in a temporary vector
- int i = 0;
- for (vector<string>::iterator r = tmp_titles.begin(); r != tmp_titles.end(); r++, i++)
- {
- // search for it in the main list
- int j = 0;
- for (vector<string>::iterator p = FileTitle.begin(); p != FileTitle.end(); p++, j++)
- // if both name and title match then remove it from the main list
- if (*r == *p && tmp_names[i] == FileName[j])
- {
- //logfile << "REMOVE: " << *r << " - " << *p << "\t\t\t" << tmp_names[i] << " - " << FileName[j] << endl;
- FileTitle[j] = "null";
- FileName[j] = "null";
- break;
- };
- }
- }
- }
- // Make a copy for verifying infolists
- FileTitle2 = FileTitle;
- // Browse sub-directories
- for (recursive_directory_iterator i("."), end; i!=end; ++i)
- {
- string filename = i->path().filename();
- string extension = filename.substr(filename.length()-3, 3);
- // If current file is an infolist
- if (filename.compare("_Info.txt") == 0)
- InfoToVector(i->path(), InfoTitle);
- // If current file is not a directory and not a text
- if (!is_directory(i->path()) && extension!="txt")
- {
- // then search for it in a vector
- int j = 0;
- for (vector<string>::iterator q = FileName.begin(); q != FileName.end(); q++, j++)
- // if found then remove
- if (*q == filename)
- {
- FileTitle[j] = "null";
- FileName[j] = "null";
- continue;
- };
- };
- };
- // Save remaining vector contents to the log file
- logfile << "FILES THAT WEREN'T FOUND:\n\n";
- int j = 0;
- for (vector<string>::iterator q=FileName.begin(); q!=FileName.end(); q++, j++)
- if (*q != "null")
- logfile << "\t" << *q << " - " << FileTitle[j] << endl;
- // Finish with info lists
- // Subtract InfoTitle from FileTitle2
- // For each entry in FileTitle2
- int I = 0;
- for (vector<string>::iterator q = FileTitle2.begin(); q != FileTitle2.end(); q++, I++)
- {
- //logfile << "item to find: " << *q << endl;
- // search for it in the InfoList
- int J = 0;
- for (vector<string>::iterator r = InfoTitle.begin(); r != InfoTitle.end(); r++, J++)
- {
- //logfile << "\titerating: " << *r << endl;
- string qq = *q;
- string rr = *r;
- // if found then remove
- if (rr.compare(0, rr.length(), qq) == 0)
- {
- FileTitle2[I] = "null";
- InfoTitle[J] = "null";
- break;
- };
- };
- };
- // Output result
- logfile << "\n\n\n\nINFO THAT WASN'T FOUND:\n\n" << "FileTitle2:\n\n";
- VectorToLog(FileTitle2);
- logfile << "\n\nInfoTitle:\n\n";
- VectorToLog(InfoTitle);
- logfile.close();
- return 0;
- }
- //-------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement