daily pastebin goal
63%
SHARE
TWEET

Verifying my GameFront OFP Backup 2

Faguss May 19th, 2016 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Program for verifying GameFront OFP backup
  2. // 1. Check if files listed in MainList.txt really exist in the sub-directories
  3. // 2. Check if files listed in MainList.txt are also listed in _Info.txt
  4.  
  5.  
  6.  
  7. // Headers:
  8. #include "stdafx.h"     // VS'13
  9. #include <list>         // std::list
  10. #include <windows.h>    // winapi
  11. #include <filesystem>   // directory iterator
  12.  
  13. // Namespaces:
  14. using namespace std;
  15. using namespace std::tr2::sys;      // directory iterator
  16.  
  17. // Global variables:
  18. ofstream logfile;
  19.  
  20.  
  21.  
  22.  
  23.  
  24. // Functions:
  25. //-------------------------------------------------------------------------------
  26. // Open main list, extract titles & names and put them to list
  27. void MainListToSTDList(string filename, list<string>& data)
  28. {
  29.     // Open file
  30.     fstream listfile;
  31.     listfile.open(filename, ios::in);
  32.  
  33.     if (!listfile.is_open())
  34.         return;
  35.  
  36.     // Copy text to a string
  37.     string content((istreambuf_iterator<char>(listfile)), istreambuf_iterator<char>());
  38.  
  39.     // Parse
  40.     size_t uploaded = content.find("Uploaded:");
  41.  
  42.     while (uploaded != string::npos)
  43.     {
  44.         // Line after "uploaded" contains title
  45.         size_t TitleStart = content.find("\n", uploaded);
  46.         size_t TitleEnd   = content.find("\n", TitleStart+1);
  47.  
  48.         // Extract title
  49.         string Title      = content.substr(TitleStart+1, TitleEnd-TitleStart-1);
  50.  
  51.         // Two lines after title there is a filename
  52.         size_t FileStart  = content.find_first_not_of(" \t\f\v\n\r", TitleEnd);
  53.         size_t FileEnd    = content.find(" |", FileStart);
  54.  
  55.         // Extract filename
  56.         string FileName   = content.substr(FileStart, FileEnd-FileStart);
  57.  
  58.         // Copy extracted data to the list
  59.         data.push_back(Title + "\a" + FileName);
  60.  
  61.         // Find next occurence
  62.         uploaded = content.find("Uploaded:", uploaded+1);
  63.     };
  64.  
  65.     listfile.close();
  66. };
  67. //-------------------------------------------------------------------------------
  68.  
  69.  
  70.  
  71.  
  72.  
  73. //-------------------------------------------------------------------------------
  74. // Open info list, extract all titles and put them to a list
  75. void InfoTextToSTDList(string filename, list<string>& titles)
  76. {
  77.     //logfile << "\tfile:" << filename << endl;
  78.  
  79.     // Open file
  80.     fstream info;
  81.     info.open(filename, ios::in);
  82.  
  83.     if (!info.is_open())
  84.         return;
  85.  
  86.     // Variables for parsing
  87.     string line;                    // holds current line
  88.     bool nextIsTitle     = true;    // copy line to list
  89.     bool nextIsSeparator = false;   // switch nextIsTitle
  90.  
  91.     // For each line
  92.     while (getline(info, line))
  93.     {
  94.         //logfile << line << endl;
  95.  
  96.         // If it's a title
  97.         if (nextIsTitle  &&  !isspace(line[0]))
  98.         {
  99.             //logfile << line << endl;
  100.  
  101.             // Copy to list
  102.             titles.push_back(line);
  103.  
  104.             // Condition to quit particular file to prevent crashing
  105.             if (filename.compare(".\\Modifications\\Add Ons\\Weapons\\_Info.txt") == 0  &&  line == "[PSOL] DesertEagle.zip")
  106.                 break;
  107.  
  108.             nextIsTitle = false;
  109.         };
  110.  
  111.         // "Popularity" precedes separator
  112.         if (line.compare(0, 11, "Popularity:") == 0)
  113.             nextIsSeparator = true;
  114.  
  115.         // If it's a item separator
  116.         if (nextIsSeparator  &&  line.compare(0, 3, "===") == 0)
  117.             nextIsSeparator = false,
  118.             nextIsTitle     = true;
  119.     };
  120.  
  121.     info.close();
  122. };
  123. //-------------------------------------------------------------------------------
  124.  
  125.  
  126.  
  127.  
  128.  
  129. //-------------------------------------------------------------------------------
  130. // Log list contents
  131. void STDListToLog(list<string>& var)
  132. {
  133.     for (list<string>::iterator q = var.begin(); q != var.end(); q++)
  134.     {
  135.         // Replace \a with dash
  136.         string currentRecord = *q;
  137.         size_t separator     = currentRecord.find("\a");
  138.  
  139.         if (separator != string::npos)
  140.             currentRecord.replace(separator, 1, " - ");
  141.  
  142.         logfile << "\t" << currentRecord << endl;
  143.     };
  144. };
  145. //-------------------------------------------------------------------------------
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. //-------------------------------------------------------------------------------
  153. // Our program
  154. int _tmain(int argc, _TCHAR* argv[])
  155. {
  156.     // Start logging
  157.     logfile.open("logfile.txt", ios::out | ios::trunc);
  158.  
  159.  
  160.     // Create lists
  161.     list<string> data;
  162.     list<string> data2;
  163.     list<string> InfoTitle;
  164.  
  165.     // Fill list
  166.     MainListToSTDList("MainList.txt", data);
  167.  
  168.  
  169.     // Find out if this is the "Operation Flashpoint" folder
  170.     char buffer[MAX_PATH];
  171.     GetModuleFileNameA(NULL, buffer, MAX_PATH);
  172.     string exepath = string(buffer);
  173.  
  174.     // If it is then we need to remove files from the other games
  175.     if (exepath.find("\\Operation Flashpoint\\") != string::npos)
  176.     {
  177.         // list of other directories
  178.         list<string> dirs
  179.         {
  180.             "Operation Flashpoint 2 Dragon Rising",
  181.             "Operation Flashpoint Dragon Rising Red River",
  182.             "Operation Flashpoint Elite",
  183.             "Operation Flashpoint Red River",
  184.             "Operation Flashpoint Resistance"
  185.         };
  186.  
  187.         // temporary list
  188.         list<string> tmp_data;
  189.  
  190.         // iterate through the dir list
  191.         for (list<string>::iterator q = dirs.begin(); q != dirs.end(); q++)
  192.         {
  193.             tmp_data.clear();
  194.  
  195.             // Get main lists from the other folders to a temporary list
  196.             string filename = "..\\" + *q + "\\MainList.txt";
  197.             MainListToSTDList(filename, tmp_data);
  198.  
  199.             // for each entry in a temporary list
  200.             for (list<string>::iterator r = tmp_data.begin(); r != tmp_data.end(); r++)
  201.             {
  202.                 //logfile << "\t" << *r << endl;
  203.  
  204.                 // Get filename and title from the current record
  205.                 string currentRecord = *r;
  206.                 size_t separator     = currentRecord.find_first_of("\a");
  207.                 string tmp_title     = currentRecord.substr(0, separator);
  208.                 string tmp_filename  = currentRecord.substr(separator + 1);
  209.                
  210.                 // search for it in the main list
  211.                 for (list<string>::iterator p = data.begin(); p != data.end(); p++)
  212.                 {
  213.                     //logfile << "\t\t" << *p << endl;
  214.  
  215.                     // Get filename and title from the current record
  216.                     string currentRecord = *p;
  217.                     size_t separator     = currentRecord.find_first_of("\a");
  218.                     string data_title    = currentRecord.substr(0, separator);
  219.                     string data_filename = currentRecord.substr(separator + 1);
  220.  
  221.                     // if both name and title match then remove it from the main list
  222.                     if (data_title == tmp_title  &&  tmp_filename == data_filename)
  223.                     {
  224.                         //logfile << "REMOVE: " << data_title << " - " << tmp_title << "\t\t\t" << tmp_filename << " - " << data_filename << endl;
  225.  
  226.                         data.erase(p);
  227.                         break;
  228.                     }
  229.                 }
  230.             }
  231.         }
  232.     }
  233.    
  234.     // Make a copy for verifying infolists
  235.     data2 = data;
  236.  
  237.  
  238.  
  239.    
  240.     // Browse sub-directories
  241.     for (recursive_directory_iterator i("."), end;  i!=end;  ++i)
  242.     {
  243.         string filename  = i->path().filename();
  244.         string extension = filename.substr(filename.length()-3, 3);
  245.        
  246.         // If current file is an infolist
  247.         if (filename.compare("_Info.txt") == 0)
  248.             InfoTextToSTDList(i->path(), InfoTitle);
  249.  
  250.         // If current file is not a directory and not a text
  251.         if (!is_directory(i->path())  &&  extension!="txt")
  252.         {
  253.             // then search for it in a list
  254.             for (list<string>::iterator q = data.begin(); q != data.end(); )
  255.             {
  256.                 // Get filename from the current list record
  257.                 string currentRecord = *q;
  258.                 size_t separator     = currentRecord.find_first_of("\a");
  259.                 string dataFileName  = currentRecord.substr(separator + 1);
  260.  
  261.                 // if match then remove from the list
  262.                 if (dataFileName == filename)
  263.                 {
  264.                     data.erase(q);
  265.                     break;
  266.                 }
  267.                 else
  268.                     q++;
  269.             };
  270.         };
  271.     };
  272.  
  273.    
  274.     // Save remaining list contents to the log file
  275.     logfile << "FILES THAT WEREN'T FOUND:\n\n";
  276.     STDListToLog(data);
  277.            
  278.  
  279.  
  280.  
  281.  
  282.        
  283.     // Finish doing work with info lists
  284.     // Subtract InfoTitle from data2
  285.  
  286.     // For each entry in data2
  287.     for (list<string>::iterator q = data2.begin(); q != data2.end(); )
  288.     {
  289.         //logfile << "item to find: " << *q << endl;
  290.         bool found = false;
  291.  
  292.         // Get filename from the current list record
  293.         string currentRecord = *q;
  294.         size_t separator     = currentRecord.find_first_of("\a");
  295.         string dataTitle     = currentRecord.substr(0, separator);
  296.  
  297.         // search for it in the info list
  298.         for (list<string>::iterator r = InfoTitle.begin(); r != InfoTitle.end();)
  299.         {
  300.             //logfile << "\titerating: " << *r << endl;
  301.  
  302.             string currentTitle = *r;
  303.  
  304.             // if match then remove
  305.             if (currentTitle.compare(0, currentTitle.length(), dataTitle) == 0)
  306.             {
  307.                 found = true;
  308.                 q = data2.erase(q);
  309.                 InfoTitle.erase(r);
  310.                 break;
  311.             }
  312.             else
  313.                 r++;
  314.         };
  315.  
  316.         if (!found)
  317.             q++;
  318.     };
  319.  
  320.     // Output result
  321.     logfile << "\n\n\n\nINFO THAT WASN'T FOUND:\n\n" << "data2:\n\n";
  322.     STDListToLog(data2);
  323.  
  324.     logfile << "\n\nInfoTitle:\n\n";
  325.     STDListToLog(InfoTitle);
  326.    
  327.  
  328.     logfile.close();
  329.     return 0;
  330. }
  331. //-------------------------------------------------------------------------------
RAW Paste Data
Top