Skip to content

Commit fe7077c

Browse files
committed
added file editor for removing directories and added console request input for seperation
1 parent 9165515 commit fe7077c

File tree

7 files changed

+142
-12
lines changed

7 files changed

+142
-12
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ set(CMAKE_CXX_STANDARD 26)
55

66
find_package(CURL REQUIRED)
77

8-
add_executable(modpack-updater src/main.cpp src/download.cpp src/download.h)
8+
add_executable(
9+
modpack-updater
10+
src/main.cpp
11+
src/download.cpp
12+
src/download.h
13+
src/file_editor.cpp
14+
src/file_editor.h
15+
src/console.cpp
16+
src/console.h
17+
)
918

1019
target_link_libraries(modpack-updater PRIVATE CURL::libcurl)

src/console.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Created by Tom Handrick on 14.06.25.
3+
//
4+
5+
#include <iostream>
6+
#include <string>
7+
8+
using namespace std;
9+
10+
string request_input(const string& message) {
11+
string input;
12+
cout << message;
13+
getline(cin, input);
14+
cout << endl;
15+
return input;
16+
}

src/console.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Created by Tom Handrick on 14.06.25.
3+
//
4+
5+
#ifndef CONSOLE_H
6+
#define CONSOLE_H
7+
8+
#include <iostream>
9+
#include <string>
10+
11+
using namespace std;
12+
13+
string request_input(const string& message);
14+
15+
#endif //CONSOLE_H

src/download.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <fstream>
44
#include <curl/curl.h>
55
#include <sys/stat.h>
6-
#include <sys/types.h>
6+
77
#ifdef _WIN32
88
#include <direct.h>
99
#define MKDIR(dir) _mkdir(dir)

src/file_editor.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Created by Tom Handrick on 14.06.25.
3+
//
4+
5+
#include "file_editor.h"
6+
7+
#include <utility>
8+
9+
using namespace std;
10+
11+
FileEditor::FileEditor(filesystem::path path) {
12+
FileEditor::path = move(path);
13+
}
14+
15+
void FileEditor::removeDirectory(const filesystem::path &name) const {
16+
filesystem::remove_all(path / name);
17+
}
18+
19+
void FileEditor::removeFile(const filesystem::path &name) const {
20+
filesystem::remove(path / name);
21+
}
22+
23+
void FileEditor::unzip(const filesystem::path &zip) const {
24+
25+
}
26+

src/file_editor.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Created by Tom Handrick on 14.06.25.
3+
//
4+
5+
#ifndef FILE_EDITOR_H
6+
#define FILE_EDITOR_H
7+
8+
#include <filesystem>
9+
10+
using namespace std;
11+
12+
class FileEditor {
13+
filesystem::path path;
14+
15+
public:
16+
explicit FileEditor(filesystem::path path);
17+
18+
void removeDirectory(const filesystem::path& name) const;
19+
20+
void removeFile(const filesystem::path& name) const;
21+
22+
void unzip(const filesystem::path& zip) const;
23+
};
24+
25+
26+
#endif //FILE_EDITOR_H

src/main.cpp

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,53 @@
11
#include <iostream>
22
#include "download.h"
3+
#include "file_editor.h"
4+
#include "console.h"
5+
#include <vector>
6+
7+
using namespace std;
38

49
int main() {
5-
const Download downloader(
6-
"https://eztxm.de/assets/images/logo.png",
7-
"/Users/eztxmmc/Downloads/logo.png"
8-
);
9-
if (downloader.download()) {
10-
std::cout << "Logo loaded successfully!" << std::endl;
11-
return 0;
12-
}
13-
std::cerr << "Error loading logo" << std::endl;
14-
return 1;
10+
vector<string> enviroments = {"client", "server"};
11+
cout << "Welcome to the Minecraft Modpack Downloader!" << endl;
12+
cout << "------------------------------------------" << endl;
13+
cout << "This program will download a Minecraft modpack from a given URL." << endl;
14+
cout << "------------------------------------------" << endl;
15+
const filesystem::path path = request_input("Enter path to download to: ");
16+
const string zipName = request_input("Enter zip name: ") + ".zip";
17+
const string url = request_input("Enter URL to download from: ");
18+
string enviroment;
19+
while (find(enviroments.begin(), enviroments.end(), enviroment) == enviroments.end()) {
20+
enviroment = request_input("Enter environment to download for: ");
21+
if (find(enviroments.begin(), enviroments.end(), enviroment) == enviroments.end()) {
22+
cerr << "Invalid environment, please enter either 'client' or 'server'" << endl;
23+
cout << "------------------------------------------" << endl;
24+
cout << "Press enter to reenter environment...";
25+
cin.get();
26+
cin.ignore();
27+
cout << "------------------------------------------" << endl;
28+
}
29+
}
30+
if (find(enviroments.begin(), enviroments.end(), enviroment) == enviroments.end()) {
31+
cerr << "Invalid environment, please enter either 'client' or 'server'" << endl;
32+
return 1;
33+
}
34+
cout << endl;
35+
filesystem::path zipPath = path / zipName;
36+
if (const Download downloader(url, zipPath); !downloader.download()) {
37+
cerr << "Error downloading " << url << endl;
38+
return 1;
39+
}
40+
cout << url << " loaded successfully!" << endl;
41+
const FileEditor editor(path);
42+
editor.removeDirectory("config");
43+
editor.removeDirectory("defaultconfigs");
44+
editor.removeDirectory("kubejs");
45+
editor.removeDirectory("logs");
46+
editor.removeDirectory("mods");
47+
if (enviroment == "client") {
48+
editor.removeDirectory("resourcepacks");
49+
editor.removeDirectory("shaderpacks");
50+
}
51+
52+
return 0;
1553
}

0 commit comments

Comments
 (0)