-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleter.cpp
More file actions
110 lines (87 loc) · 4.29 KB
/
Copy pathDeleter.cpp
File metadata and controls
110 lines (87 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "Header.h"
#include <iostream>
#include <fstream>
#include <string>
#include <limits>
#include <iomanip>
#include <filesystem>
#include <vector>
#include <string>
#ifdef _WIN32
#include <windows.h>
#else
#include <thread>
#include <chrono>
#endif
inline void ListSaveFiles() {
std::cout << "\n┌───────────────────────────────────────────────────┐\n";
std::cout << "│ EXISTING SAVES │\n";
std::cout << "├───────────────────────────────────────────────────┤\n";
WIN32_FIND_DATAA findFileData;
HANDLE hFind = FindFirstFileA("*.txt", &findFileData);
if (hFind == INVALID_HANDLE_VALUE) {
std::cout << "│ No saves found. │\n";
std::cout << "└───────────────────────────────────────────────────┘\n";
return;
}
bool found = false;
int count = 0;
do {
if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
std::cout << "│ " << (++count) << ". " << findFileData.cFileName << "Delete ?"<<"\n";
found = true;
}
} while (FindNextFileA(hFind, &findFileData) != 0);
FindClose(hFind);
if (!found) {
std::cout << "│ No saves found. │\n";
}
std::cout << "└───────────────────────────────────────────────────┘\n";
}
void Deleter() {
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::vector<std::string> saveFiles;
WIN32_FIND_DATAA findFileData;
HANDLE hFind = FindFirstFileA("*.txt", &findFileData);
std::cout << "\n┌───────────────────────────────────────────────────┐\n";
std::cout << "│ DELETE SAVE │\n";
std::cout << "├───────────────────────────────────────────────────┤\n";
if (hFind == INVALID_HANDLE_VALUE) {
std::cout << "│ No saves found. │\n";
std::cout << "└───────────────────────────────────────────────────┘\n";
return;
}
int count = 0;
do {
if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
saveFiles.push_back(findFileData.cFileName);
std::cout << "│ " << ++count << ". " << findFileData.cFileName << "\n";
}
} while (FindNextFileA(hFind, &findFileData) != 0);
FindClose(hFind);
if (saveFiles.empty()) {
std::cout << "│ No saves found. │\n";
std::cout << "└───────────────────────────────────────────────────┘\n";
return;
}
std::cout << "└───────────────────────────────────────────────────┘\n";
std::cout << "Enter save number to delete it: ";
std::string num_delete_save;
std::getline(std::cin, num_delete_save);
if (num_delete_save.empty()) {
std::cout << "\n[!] Cancelled.\n";
return;
}
int index = std::stoi(num_delete_save) - 1;
if (index < 0 || index >= saveFiles.size()) {
std::cout << "\n[!] Invalid number!\n";
return;
}
const std::string& filename = saveFiles[index];
std::error_code ec;
if (std::filesystem::remove(filename, ec)) {
std::cout << "\n[SUCCESS] File '" << filename << "' deleted successfully!\n";
} else {
std::cout << "\n[ERROR] Error deleting file: " << ec.message() << '\n';
}
}