Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLHy0424 committed Nov 18, 2024
1 parent 4a5ea9f commit 0b63c20
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"${workspaceFolder}\\*"
],
"defines":[
//"_PREVIEW",
//"_PREVIEW_",
//"NDEBUG",
"_CRT_SECURE_NO_WARNINGS",
"ANSI",
Expand Down
2 changes: 1 addition & 1 deletion info.rc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include"src/info.hpp"
#ifdef _PREVIEW
#ifdef _PREVIEW_
1 ICON "img/favicon_preview.ico"
#else
1 ICON "img/favicon.ico"
Expand Down
26 changes: 13 additions & 13 deletions src/console_ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#define CONSOLE_MOUSE_CLICK_DOUBLE DOUBLE_CLICK
#define CONSOLE_MOUSE_MOVE MOUSE_MOVED
#define CONSOLE_MOUSE_WHEEL MOUSE_WHEELED
#define CONSOLE_TEXT_DEFAULT_DEFAULT 0x07
#define CONSOLE_TEXT_BLUE_DEFAULT 0x09
#define CONSOLE_TEXT_RED_DEFAULT 0x0c
#define CONSOLE_TEXT_WHITE_WHITE 0x07
#define CONSOLE_TEXT_BLUE_WHITE 0x09
#define CONSOLE_TEXT_RED_WHITE 0x0c
class console_ui final{
public:
struct fn_args final{
Expand Down Expand Up @@ -67,9 +67,9 @@ class console_ui final{
}
explicit ui_item_():
text{},
default_color{CONSOLE_TEXT_DEFAULT_DEFAULT},
highlight_color{CONSOLE_TEXT_BLUE_DEFAULT},
last_color{CONSOLE_TEXT_DEFAULT_DEFAULT},
default_color{CONSOLE_TEXT_WHITE_WHITE},
highlight_color{CONSOLE_TEXT_BLUE_WHITE},
last_color{CONSOLE_TEXT_WHITE_WHITE},
position{},
fn{}
{}
Expand All @@ -81,7 +81,7 @@ class console_ui final{
):text{_text},
default_color{_default_color},
highlight_color{_highlight_color},
last_color{CONSOLE_TEXT_DEFAULT_DEFAULT},
last_color{CONSOLE_TEXT_WHITE_WHITE},
position{},
fn{_fn}
{}
Expand Down Expand Up @@ -253,8 +253,8 @@ class console_ui final{
auto &add(
const char *const _text,
const callback_ _fn=nullptr,
const short _highlight_color=CONSOLE_TEXT_BLUE_DEFAULT,
const short _default_color=CONSOLE_TEXT_DEFAULT_DEFAULT
const short _highlight_color=CONSOLE_TEXT_BLUE_WHITE,
const short _default_color=CONSOLE_TEXT_WHITE_WHITE
){
item_.emplace_back(
ui_item_{
Expand All @@ -272,8 +272,8 @@ class console_ui final{
const size_type_ _index,
const char *const _text,
const callback_ _fn=nullptr,
const short _highlight_color=CONSOLE_TEXT_BLUE_DEFAULT,
const short _default_color=CONSOLE_TEXT_DEFAULT_DEFAULT
const short _highlight_color=CONSOLE_TEXT_BLUE_WHITE,
const short _default_color=CONSOLE_TEXT_WHITE_WHITE
){
item_.emplace(
item_.begin()+_index,
Expand All @@ -292,8 +292,8 @@ class console_ui final{
const size_type_ _index,
const char *const _text,
const callback_ _fn=nullptr,
const short _highlight_color=CONSOLE_TEXT_BLUE_DEFAULT,
const short _default_color=CONSOLE_TEXT_DEFAULT_DEFAULT
const short _highlight_color=CONSOLE_TEXT_BLUE_WHITE,
const short _default_color=CONSOLE_TEXT_WHITE_WHITE
){
item_.at(_index)=ui_item_{
_text,
Expand Down
4 changes: 2 additions & 2 deletions src/info.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once
#define INFO_NAME "Computer Room Control Software Nemesis"
#ifdef _PREVIEW
#ifdef _PREVIEW_
#define INFO_VERSION "v6.0.0-preview.3"
#else
#define INFO_VERSION "v5.10.3"
#endif
#define INFO_REPO_URL "https://github.com/MaxLHy0424/CRCSN"
#define INFO_DEVELOPER "MaxLHy0424"
#define INFO_LICENSE "MIT License"
#ifdef _PREVIEW
#ifdef _PREVIEW_
#define WINDOW_WIDTH 50
#define WINDOW_HEIGHT 25
#endif
20 changes: 10 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include"console_ui.hpp"
#include"mod.hpp"
#include<thread>
#ifdef _PREVIEW
#ifdef _PREVIEW_
auto main()->int{
console_ui ui;
ui.set_console(936,"CRCSN",WINDOW_WIDTH,WINDOW_HEIGHT,true,false,true,255)
Expand Down Expand Up @@ -51,7 +51,7 @@ auto main(const int _argc,const char *const _argv[])->int{
}
mod::init();
#endif
#ifdef _PREVIEW
#ifdef _PREVIEW_
if(config_data.enhanced_window){
std::thread{[](){
const HWND this_window{GetConsoleWindow()};
Expand Down Expand Up @@ -105,17 +105,17 @@ auto main(const int _argc,const char *const _argv[])->int{
}
#endif
ui.add(" [ 主 页 ]\n\n");
#ifndef _PREVIEW
#ifndef _PREVIEW_
if(config_error){
ui.add(" (!) 参数错误.\n");
}
#endif
ui.add(" < 退出 ",mod::exit,CONSOLE_TEXT_RED_DEFAULT)
#ifdef _PREVIEW
.add(" < 重启 ",mod::relaunch_as_admin,CONSOLE_TEXT_RED_DEFAULT)
ui.add(" < 退出 ",mod::quit,CONSOLE_TEXT_RED_WHITE)
#ifdef _PREVIEW_
.add(" < 重启 ",mod::relaunch_as_admin,CONSOLE_TEXT_RED_WHITE)
#endif
.add(" > 信息 ",mod::info)
#ifdef _PREVIEW
#ifdef _PREVIEW_
.add(" > 配置 ",mod::config_op{'w'})
.add(" > 工具箱 ",mod::toolkit)
#else
Expand All @@ -124,13 +124,13 @@ auto main(const int _argc,const char *const _argv[])->int{
.add("\n[破解]\n")
.add(" > 极域电子教室 ",mod::rule_op{'c',mod::rule_data::mythware})
.add(" > 联想云教室 ",mod::rule_op{'c',mod::rule_data::lenovo})
#ifdef _PREVIEW
#ifdef _PREVIEW_
.add(" > 自定义 ",mod::rule_op{'c',mod::rule_data::customized})
#endif
.add("\n[恢复]\n")
.add(" > 极域电子教室 ",mod::rule_op{'r',mod::rule_data::mythware})
.add(" > 联想云教室 ",mod::rule_op{'r',mod::rule_data::lenovo})
#ifdef _PREVIEW
#ifdef _PREVIEW_
.add(" > 自定义 ",mod::rule_op{'r',mod::rule_data::customized})
.set_console(
936,
Expand All @@ -147,7 +147,7 @@ auto main(const int _argc,const char *const _argv[])->int{
#endif
.show()
.lock(false,false);
#ifdef _PREVIEW
#ifdef _PREVIEW_
if(config_data.enhanced_window){
SetWindowLongPtrA(
GetConsoleWindow(),GWL_STYLE,
Expand Down
20 changes: 10 additions & 10 deletions src/mod.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#pragma once
#include"info.hpp"
#include"console_ui.hpp"
#ifdef _PREVIEW
#ifdef _PREVIEW_
#include<fstream>
#endif
inline struct{
#ifdef _PREVIEW
#ifdef _PREVIEW_
bool enhanced_op,enhanced_window,protected_mode;
#else
bool front_show_window,translucent_window,window_ctrls;
#endif
}config_data{};
#ifndef _PREVIEW
#ifndef _PREVIEW_
inline bool config_error{};
#endif
namespace mod{
namespace rule_data{
struct base final{
#ifdef _PREVIEW
#ifdef _PREVIEW_
std::vector<std::string> exe,svc;
#else
std::vector<const char*> exe,svc;
Expand Down Expand Up @@ -82,10 +82,10 @@ namespace mod{
}
return is_admin;
}
inline auto exit(console_ui::fn_args){
inline auto quit(console_ui::fn_args){
return true;
}
#ifdef _PREVIEW
#ifdef _PREVIEW_
inline auto relaunch_as_admin(console_ui::fn_args){
char *const path{new char[MAX_PATH]{}};
GetModuleFileNameA(nullptr,path,MAX_PATH);
Expand All @@ -100,7 +100,7 @@ namespace mod{
}};
console_ui ui;
ui.add(" [ 信 息 ]\n\n")
.add(" < 返回 ",mod::exit,CONSOLE_TEXT_RED_DEFAULT)
.add(" < 返回 ",quit,CONSOLE_TEXT_RED_WHITE)
.add(
"\n[名称]\n\n"
" " INFO_NAME "\n"
Expand Down Expand Up @@ -183,7 +183,7 @@ namespace mod{
};
console_ui ui;
ui.add(" [ 工 具 箱 ]\n\n")
.add(" < 返回 ",mod::exit,CONSOLE_TEXT_RED_DEFAULT)
.add(" < 返回 ",quit,CONSOLE_TEXT_RED_WHITE)
.add(" > 命令提示符 ",std::move(open_cmd_prompt))
.add("\n[快捷操作]\n")
.add(" > 重启资源管理器 ",exec_cmd{cmds[0]})
Expand Down Expand Up @@ -315,7 +315,7 @@ namespace mod{
console_ui ui;
ui.add(" [ 配 置 ]\n\n")
.add(" (i) 相关信息可参阅文档.\n")
.add(" < 同步配置并返回 ",std::move(sync),CONSOLE_TEXT_RED_DEFAULT)
.add(" < 同步配置并返回 ",std::move(sync),CONSOLE_TEXT_RED_WHITE)
.add(" > 打开配置文件 ",std::move(open_config_file))
.add("\n[增强操作]\n")
.add(" > 启用 ",[](console_ui::fn_args){config_data.enhanced_op=true;return false;})
Expand Down Expand Up @@ -474,7 +474,7 @@ namespace mod{
inline auto info(console_ui::fn_args){
console_ui ui;
ui.add(" [ 信 息 ]\n\n")
.add(" < 返回 ",mod::exit,CONSOLE_TEXT_RED_DEFAULT)
.add(" < 返回 ",quit,CONSOLE_TEXT_RED_WHITE)
.add(
"\n[名称]\n\n"
" " INFO_NAME "\n"
Expand Down

0 comments on commit 0b63c20

Please sign in to comment.