fork download
  1. /*
  2. * Switch GTA 1.0 or 3.0 to open
  3. * by Fábio
  4. * http://g...content-available-to-author-only...t.com/
  5. * http://b...content-available-to-author-only...s.com/
  6. * More info about this program: http://b...content-available-to-author-only...s.com/t2903-
  7. *
  8. * Licensed under WTFPLv2 (http://w...content-available-to-author-only...l.net/txt/copying/)
  9. */
  10. #include <fstream>
  11. #include <iostream>
  12. #include <string>
  13. //#include <cstring>
  14. //#include <cstdlib>
  15. #include <vector>
  16. #include <cstdio>
  17. #include <exception>
  18. #include <Windows.h>
  19. #include "dirent.h"
  20.  
  21. void uninstallMods();
  22. void installMods();
  23.  
  24. int main(){
  25. switch(MessageBox(0, "Deseja iniciar o GTA com mods?", "Pergunta", MB_YESNOCANCEL)){
  26. case IDCANCEL:
  27. break;
  28.  
  29. case IDNO:
  30. uninstallMods();
  31. system(".\\gta-sa.exe");
  32. break;
  33.  
  34. case IDYES:
  35. installMods();
  36. system(".\\gta_sa.exe");
  37. break;
  38.  
  39. default:
  40. break;
  41. }
  42. return 0;
  43. }
  44.  
  45. class Exception : std::exception{
  46. std::string whatString;
  47.  
  48. public:
  49. const char *what(){
  50. return whatString.c_str();
  51. }
  52.  
  53. Exception(const char *WhatStr) : std::exception(){
  54. whatString = WhatStr;
  55. MessageBox(0, WhatStr, "Error!!!", 0); // Show error string
  56. }
  57. };
  58.  
  59. struct fileContent{
  60. std::streamsize size;
  61. char *Content;
  62.  
  63. fileContent(){
  64. size = 0L;
  65. Content = nullptr;
  66. }
  67. };
  68.  
  69. template<class T>
  70. std::streamsize FileSize(T &fileStream){
  71. fileStream.seekg(0, fileStream.end);
  72. std::streamsize size = fileStream.tellg();
  73. fileStream.seekg(0, fileStream.beg);
  74. return size;
  75. }
  76.  
  77. template<class T>
  78. fileContent readFile(T &fileStream){
  79. fileContent FContent;
  80.  
  81. FContent.size = FileSize(fileStream);
  82. FContent.Content = new char[FContent.size + 1];
  83. memset(FContent.Content, 0, FContent.size + 1);
  84.  
  85. fileStream.read(FContent.Content, FContent.size);
  86.  
  87. std::cout << "Config file size is: " << FContent.size << "\n";
  88.  
  89. return FContent;
  90. }
  91.  
  92. typedef void (*fileCallbackFunction)(const char *, const char *); // callback function type
  93.  
  94. void toCallBack(const char *fileName, const char *fullName){ // Function LoopFiles callback (RLY?)
  95. if(MoveFileA(fullName, fileName)){
  96. std::cout << "Moved " << fileName << "\n";
  97. }
  98. }
  99.  
  100. std::vector<std::string> listOfModsToMove;
  101. std::fstream configFile;
  102.  
  103. bool isInList(const char *name){ // Check if file is in list of mods to move
  104. for(unsigned int i = 0, size = listOfModsToMove.size(); i < size; i++){
  105. if(listOfModsToMove[i] == name) return true;
  106. }
  107. return false;
  108. }
  109.  
  110. void LoopFiles(const char *Folder, fileCallbackFunction callback){ // Get folder files
  111. struct dirent *pent = nullptr;
  112. DIR *ScriptsFolder = nullptr;
  113.  
  114. ScriptsFolder = opendir(Folder); // Open directory
  115. if(ScriptsFolder == nullptr) return; // Return if directory doesn't openned
  116. std::string FileName;
  117.  
  118. while(pent = readdir(ScriptsFolder)){
  119. if(isInList(pent->d_name)){
  120. FileName = Folder;
  121. FileName += "\\";
  122. FileName += pent->d_name; // Folder\\Name Of Searched File
  123. callback(pent->d_name, FileName.c_str()); // call the callback
  124. }
  125. }
  126. }
  127.  
  128. void ParseConfig(const char *configFileName){ // Get list of mods in configuration file
  129. std::cout << "Openning configuration file\n";
  130. configFile.open(configFileName, std::ios::in | std::ios::out); // Open config file to i/o
  131. if(!configFile.is_open()){ // Open fail?
  132. configFile.open(configFileName, std::ios::out); // Create file
  133.  
  134. if(!configFile.is_open()) throw Exception("Can't create configuration file!!!"); // Creation failed?
  135. configFile.close(); // Created with sucessfull
  136.  
  137. configFile.open(configFileName, std::ios::in | std::ios::out); // Open file to i/o
  138. }
  139.  
  140. std::cout << "Reading configuration file\n";
  141. fileContent cfgContent = readFile(configFile);
  142.  
  143. std::cout << "Getting mods to move list\n";
  144.  
  145. unsigned int sPoint = 0, ePoint = 0;
  146.  
  147. for(unsigned int i = 0; i < cfgContent.size; i++, ePoint++){
  148. if(cfgContent.Content[i] == '\n'){
  149. cfgContent.Content[i] = 0;
  150. if(sPoint != ePoint) listOfModsToMove.push_back(&cfgContent.Content[sPoint]);
  151.  
  152. sPoint = ePoint = i++;
  153. }
  154. }
  155.  
  156. if(sPoint != ePoint && cfgContent.Content[sPoint] != '\n') listOfModsToMove.push_back(&cfgContent.Content[sPoint]);
  157.  
  158. std::cout << "Search finished\n";
  159.  
  160. configFile.close();
  161. }
  162.  
  163. void uninstallMods(){ // Remove mods from game folder
  164. ParseConfig("Mods to Move list.cfg");
  165. std::string fullNamePath;
  166.  
  167. for(unsigned int i = 0, size = listOfModsToMove.size(); i < size; i++){
  168. fullNamePath = ".\\Mods\\";
  169. fullNamePath += listOfModsToMove.at(i).c_str();
  170.  
  171. if(MoveFileA(listOfModsToMove.at(i).c_str(), fullNamePath.c_str())){
  172. std::cout << "Moved " << listOfModsToMove.at(i).c_str() << "\n";
  173. }
  174. }
  175. }
  176.  
  177. void installMods(){ // Put mods on game folder
  178. ParseConfig("Mods to Move list.cfg");
  179.  
  180. LoopFiles("Mods", toCallBack);
  181. }
  182.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty