Skip to content

Commit 9be45b7

Browse files
Fomin PetrFomin Petr
authored andcommitted
Url fix
1 parent 49cc7e4 commit 9be45b7

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

Program.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
#include <urlmon.h>
77

88
#pragma comment(lib, "urlmon.lib")
9-
void SetConsoleOutputCP() {
109

10+
void SetConsoleOutputCP() {
1111
SetConsoleOutputCP(CP_UTF8);
1212
}
1313

14+
void OpenWebsite(const std::string& url) {
15+
ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
16+
}
17+
1418
void DownloadFile(const std::string& url, const std::string& outputPath) {
1519
HRESULT result = URLDownloadToFileA(NULL, url.c_str(), outputPath.c_str(), 0, NULL);
1620
if (SUCCEEDED(result)) {
@@ -26,11 +30,9 @@ void LaunchFile(const std::string& filePath) {
2630
}
2731

2832
int main() {
29-
3033
SetConsoleOutputCP();
3134
setlocale(LC_ALL, "Russian");
3235

33-
3436
std::vector<std::string> fileUrls = {
3537
"https://www.7-zip.org/a/7z2408-x64.exe",
3638
"https://github.com/ShareX/ShareX/releases/download/v16.1.0/ShareX-16.1.0-setup.exe",
@@ -47,7 +49,10 @@ int main() {
4749
"https://github.com/windirstat/windirstat/releases/download/release%2Fv2.0.3/WinDirStat-x64.msi",
4850
"https://download01.logi.com/web/ftp/pub/techsupport/gaming/lghub_installer.exe",
4951
"https://vscode.download.prss.microsoft.com/dbazure/download/stable/f1a4fb101478ce6ec82fe9627c43efbf9e98c813/VSCodeUserSetup-x64-1.95.3.exe",
50-
"https://dl.ocbase.com/per/stable/OCCT.exe"
52+
"https://dl.ocbase.com/per/stable/OCCT.exe",
53+
"https://cdn.fastly.steamstatic.com/client/installer/SteamSetup.exe",
54+
"https://www.fosshub.com/qBittorrent.html",
55+
"https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7BFD415EAD-8A45-A037-D5CB-E8CB4B8AA2A9%7D%26lang%3Dru%26browser%3D4%26usagestats%3D1%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-statsdef_1%26installdataindex%3Dempty/update2/installers/ChromeSetup.exe"
5156
};
5257

5358
std::vector<std::string> fileNames = {
@@ -66,15 +71,16 @@ int main() {
6671
"WinDirStat",
6772
"Logitech G HUB",
6873
"Visual Studio Code",
69-
"OCCT"
74+
"OCCT",
75+
"Steam",
76+
"qbittorrent",
77+
"Google Chrome"
7078
};
7179

72-
7380
std::string downloadFolder;
7481
char* buffer = nullptr;
7582
size_t size;
7683

77-
7884
if (_dupenv_s(&buffer, &size, "USERPROFILE") == 0) {
7985
downloadFolder = std::string(buffer) + "\\Documents\\DownloadedFiles";
8086
free(buffer);
@@ -94,24 +100,28 @@ int main() {
94100
std::string input;
95101
std::getline(std::cin, input);
96102

97-
98103
std::vector<int> selectedFiles;
99104
size_t pos = 0;
100105
while ((pos = input.find(' ')) != std::string::npos) {
101106
selectedFiles.push_back(std::stoi(input.substr(0, pos)) - 1);
102107
input.erase(0, pos + 1);
103108
}
104-
selectedFiles.push_back(std::stoi(input) - 1);
109+
selectedFiles.push_back(std::stoi(input) - 1);
105110

106111
for (int index : selectedFiles) {
107112
if (index >= 0 && index < fileUrls.size()) {
108113
std::string fileName = fileUrls[index].substr(fileUrls[index].find_last_of('/') + 1);
109114
std::string filePath = downloadFolder + "\\" + fileName;
110115

111116

112-
DownloadFile(fileUrls[index], filePath);
113-
114-
LaunchFile(filePath);
117+
if (fileUrls[index].substr(fileUrls[index].find_last_of('.') + 1) == "exe" ||
118+
fileUrls[index].substr(fileUrls[index].find_last_of('.') + 1) == "zip") {
119+
DownloadFile(fileUrls[index], filePath);
120+
LaunchFile(filePath);
121+
}
122+
else {
123+
OpenWebsite(fileUrls[index]);
124+
}
115125
}
116126
else {
117127
std::cerr << "Íåêîððåêòíûé íîìåð: " << index + 1 << std::endl;

0 commit comments

Comments
 (0)