-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
90 lines (78 loc) · 2.31 KB
/
main.cpp
File metadata and controls
90 lines (78 loc) · 2.31 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
#include <conio.h>
#include "ThemeSwitcher.h"
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
const int EXIT = 0;
/**
* メニューを表示
* 画面をクリア、利用可能なオプション表示
*/
void printMenu() {
system("cls");
cout << "Windows Theme Switcher\n";
cout << "https://github.com/nora-2222\n\n";
cout << "1. Light Theme\n";
cout << "2. Dark Theme\n";
cout << "3. Restart Explorer (for immediate effect)\n";
cout << "0. Exit\n\n";
cout << "Select number: ";
}
void printResult(const ThemeChangeResult& result) {
cout << "\n" << getErrorMessage(result) << "\n";
if (!result.success && result.systemErrorCode != 0) {
cout << "System error code: " << result.systemErrorCode << "\n";
}
cout << "\nPress Enter to return to the menu...";
char ch;
do {
ch = _getch();
} while (ch != '\r');
cout << "\n";
}
void printMessage(const char* message) {
cout << "\n" << message << "\n";
cout << "Press Enter to continue...";
cout << "\n";
}
char getValidChoice() {
char choice;
do {
printMenu(); // メニュー
choice = _getch(); // 単一文字入力を取得
if (choice != '0' && choice != '1' && choice != '2' && choice != '3') {
cout << "\nInvalid selection. Please try again.\n";
Sleep(1000);
}
} while (choice != '0' && choice != '1' && choice != '2' && choice != '3');
return choice;
}
int main() {
// メインプログラムループ
// 終了するまで継続
while (true) {
// 検証済みの入力を取得
char choice = getValidChoice();
cout << choice << "\n";
if (choice == '0') {
break;
}
else if (choice == '1' || choice == '2') {
ThemeChangeResult result = changeTheme(choice == '1' ? LIGHT_THEME : DARK_THEME);
printResult(result);
}
else if (choice == '3') {
cout << "\nRestarting Windows Explorer...\n";
bool success = restartExplorer();
if (success) {
printMessage("Explorer restarted successfully.");
}
else {
printMessage("Failed to restart Explorer. You may need administrator privileges.");
}
}
}
cout << "\nThank you for using Windows Theme Switcher!\n";
return 0;
}