1212
1313std::fstream logFile;
1414bool legacyMode = false ;
15+ const std::string logPath = " updateLog.txt" ;
1516
1617void startPorcess (LPSTR exePath)
1718{
@@ -39,8 +40,16 @@ void startPorcess(LPSTR exePath)
3940 CloseHandle (pi.hThread );
4041}
4142
43+ void initLog ()
44+ {
45+ logFile.open (logPath, std::ios::out);
46+ logFile.close ();
47+ }
48+
4249void log (std::string tag, std::string message)
4350{
51+ logFile.open (logPath, std::ios::app);
52+
4453 char buffer[256 ];
4554 auto timeNow = std::chrono::system_clock::now ();
4655 std::time_t now = std::chrono::system_clock::to_time_t (timeNow);
@@ -51,18 +60,17 @@ void log(std::string tag, std::string message)
5160 sprintf_s (buffer, " [%s] - (%s): %s\n " , ss.str ().c_str (), tag.c_str (), message.c_str ());
5261
5362 logFile.write (buffer, strlen (buffer));
63+ logFile.close ();
5464}
5565
5666int main (int argc, char * argv[])
5767{
58- logFile.open (" updateLog.txt" , std::ios::out);
5968 log (" Initialization" , " Started" );
6069
6170 FreeConsole ();
6271 if (argc < 4 )
6372 {
6473 log (" Arguments" , " Not enough arguments" );
65- logFile.close ();
6674 return -1 ;
6775 }
6876
@@ -88,13 +96,11 @@ int main(int argc, char* argv[])
8896 if (!std::filesystem::exists (exPackPath))
8997 {
9098 log (" File Checks" , " Extracted files do not exist" );
91- logFile.close ();
9299 return -1 ;
93100 }
94101 if (!std::filesystem::exists (fileListPath) && !legacyMode)
95102 {
96103 log (" File Checks" , " File list does not exist" );
97- logFile.close ();
98104 return -1 ;
99105 }
100106
@@ -138,7 +144,6 @@ int main(int argc, char* argv[])
138144 if (!std::filesystem::remove (installPath + " \\ " + file, ec))
139145 {
140146 log (" Installation" , (" Deletion failed for file: " + file).c_str ());
141- logFile.close ();
142147 return -1 ;
143148 }
144149 log (" Installation" , (installPath + " \\ " + file).c_str ());
@@ -159,8 +164,15 @@ int main(int argc, char* argv[])
159164 {
160165 for (std::string file : fileList)
161166 {
162- std::filesystem::copy (exPackPath + " \\ " + file, installPath + " \\ " + file);
163- log (" Installation" , (exPackPath + " \\ " + file + " => " + installPath + " \\ " + file).c_str ());
167+ if (std::filesystem::exists (exPackPath + " \\ " + file))
168+ {
169+ std::filesystem::copy (exPackPath + " \\ " + file, installPath + " \\ " + file);
170+ log (" Installation" , (exPackPath + " \\ " + file + " => " + installPath + " \\ " + file).c_str ());
171+ }
172+ else
173+ {
174+ log (" Installation" , (exPackPath + " \\ " + file + " not found, skipping..." ).c_str ());
175+ }
164176 }
165177 }
166178
@@ -176,6 +188,5 @@ int main(int argc, char* argv[])
176188 startPorcess ((LPSTR)exePath.c_str ());
177189
178190 log (" Finalization" , " Closing" );
179- logFile.close ();
180191 return 0 ;
181192}
0 commit comments