Skip to content

Commit adcd40d

Browse files
committed
Fixed Updater and added manifest to Updater
1 parent 0074290 commit adcd40d

37 files changed

+339
-2546
lines changed

Updater/Updater.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@
118118
<ClCompile>
119119
<WarningLevel>Level3</WarningLevel>
120120
<SDLCheck>true</SDLCheck>
121-
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
121+
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
122122
<ConformanceMode>true</ConformanceMode>
123123
<LanguageStandard>stdcpp20</LanguageStandard>
124124
</ClCompile>
125125
<Link>
126126
<SubSystem>Console</SubSystem>
127127
<GenerateDebugInformation>true</GenerateDebugInformation>
128+
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
128129
</Link>
129130
</ItemDefinitionGroup>
130131
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

Updater/main.cc

Lines changed: 131 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
#define _CRT_SECURE_NO_WARNINGS
2+
13
#include <iostream>
24
#include <string>
35
#include <filesystem>
6+
#include <fstream>
47
#include <Windows.h>
8+
#include <chrono>
9+
#include <ctime>
10+
#include <iomanip>
11+
#include <sstream>
12+
13+
std::fstream logFile;
14+
bool legacyMode = false;
515

616
void startPorcess(LPSTR exePath)
717
{
@@ -29,27 +39,143 @@ void startPorcess(LPSTR exePath)
2939
CloseHandle(pi.hThread);
3040
}
3141

42+
void log(std::string tag, std::string message)
43+
{
44+
char buffer[256];
45+
auto timeNow = std::chrono::system_clock::now();
46+
std::time_t now = std::chrono::system_clock::to_time_t(timeNow);
47+
48+
std::stringstream ss;
49+
ss << std::put_time(std::localtime(&now), "%d.%m.%Y %H:%M:%S");
50+
51+
sprintf_s(buffer, "[%s] - (%s): %s\n", ss.str().c_str(), tag.c_str(), message.c_str());
52+
53+
logFile.write(buffer, strlen(buffer));
54+
}
55+
3256
int main(int argc, char* argv[])
3357
{
58+
logFile.open("updateLog.txt", std::ios::out);
59+
log("Initialization", "Started");
60+
3461
FreeConsole();
35-
if (argc < 4) return -1;
62+
if (argc < 4)
63+
{
64+
log("Arguments", "Not enough arguments");
65+
logFile.close();
66+
return -1;
67+
}
3668

3769
std::string exPackPath = argv[1];
3870
std::string installPath = argv[2];
39-
std::string exeName = argv[3];
71+
std::string fileListPath = argv[3];
72+
std::string exeName;
73+
74+
log("Arguments", "Assigned arguments to variables");
75+
76+
if (argc >= 5) exeName = argv[4];
77+
else
78+
{
79+
log("Arguments", "Running in Legacy mode");
80+
legacyMode = true;
81+
exeName = fileListPath;
82+
fileListPath = "";
83+
}
84+
85+
86+
std::vector<std::string> fileList;
87+
88+
if (!std::filesystem::exists(exPackPath))
89+
{
90+
log("File Checks", "Extracted files do not exist");
91+
logFile.close();
92+
return -1;
93+
}
94+
if (!std::filesystem::exists(fileListPath) && !legacyMode)
95+
{
96+
log("File Checks", "File list does not exist");
97+
logFile.close();
98+
return -1;
99+
}
100+
101+
if(!legacyMode)
102+
{
103+
std::fstream fileListFile(fileListPath, std::ios::in);
104+
if (fileListFile.is_open())
105+
{
106+
log("File List Reading", "Started Reading");
107+
108+
std::string line;
109+
while (std::getline(fileListFile, line))
110+
{
111+
fileList.push_back(line);
112+
log("File List Reading", line.c_str());
113+
}
114+
fileListFile.close();
115+
116+
log("File List Reading", "Concluded Reading");
117+
}
118+
}
119+
else log("File List Reading", "Skipping due to legacy mode");
120+
40121

41-
if (!std::filesystem::exists(exPackPath)) return -1;
42122
if (std::filesystem::exists(installPath))
43123
{
44124
Sleep(2000);
45125
std::error_code ec;
46-
if (std::filesystem::remove_all(installPath, ec) == -1) return -1;
126+
127+
log("Installation", "Started Deletion");
128+
129+
if (legacyMode)
130+
{
131+
if (std::filesystem::remove_all(installPath, ec) == -1) return -1;
132+
log("Installation", "Deleted everything in installation folder due to legacy mode");
133+
}
134+
else
135+
{
136+
for (std::string file : fileList)
137+
{
138+
if (!std::filesystem::remove(installPath + "\\" + file, ec))
139+
{
140+
log("Installation", ("Deletion failed for file: " + file).c_str());
141+
logFile.close();
142+
return -1;
143+
}
144+
log("Installation", (installPath + "\\" + file).c_str());
145+
}
146+
}
147+
148+
log("Installation", "Concluded Deletion");
149+
}
150+
151+
log("Installation", "Started Copying");
152+
153+
if (legacyMode)
154+
{
155+
std::filesystem::copy(exPackPath, installPath);
156+
log("Installation", "Copying everything in extracted folder due to legacy mode");
47157
}
158+
else
159+
{
160+
for (std::string file : fileList)
161+
{
162+
std::filesystem::copy(exPackPath + "\\" + file, installPath + "\\" + file);
163+
log("Installation", (exPackPath + "\\" + file + " => " + installPath + "\\" + file).c_str());
164+
}
165+
}
166+
48167

49-
std::filesystem::copy(exPackPath, installPath);
168+
log("Installation", "Consluded Copying");
169+
log("Finalization", "Creating exe path");
50170

51171
std::string exePath = "\"" + installPath + "\\" + exeName + "\"";
172+
173+
log("Finalization", exePath.c_str());
174+
log("Finalization", "Staring exe");
175+
52176
startPorcess((LPSTR)exePath.c_str());
53177

178+
log("Finalization", "Closing");
179+
logFile.close();
54180
return 0;
55181
}

VexTrack Old/.png

Whitespace-only changes.

VexTrack Old/Updater.spec

Lines changed: 0 additions & 34 deletions
This file was deleted.

VexTrack Old/VexTrack.ico

-390 KB
Binary file not shown.

VexTrack Old/VexTrack.spec

Lines changed: 0 additions & 34 deletions
This file was deleted.

VexTrack Old/src/Updater.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)