From e6c537600d81c445b09c0895767be3a0e6d1816a Mon Sep 17 00:00:00 2001 From: MaxLHy0424 Date: Fri, 4 Oct 2024 10:56:26 +0800 Subject: [PATCH] refactor --- src/def.hpp | 3 --- src/main.cpp | 8 ++++---- src/mod.hpp | 12 ++++++------ src/ui.hpp | 36 ++++++++++++++++++------------------ 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/def.hpp b/src/def.hpp index 6d81464d..8b8a53d3 100644 --- a/src/def.hpp +++ b/src/def.hpp @@ -14,9 +14,6 @@ #include #include #include -using i8=char; -using i16=short; -using i32=int; #endif #define INFO_NAME "Computer Room Control Software Nemesis" #define INFO_VERSION "v5.8.0" diff --git a/src/main.cpp b/src/main.cpp index dd4b0f66..26b4daab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,10 +3,10 @@ #include"ui.hpp" #include"mod.hpp" #ifndef _DEV_ -auto main(const i32 argc,const i8 *const args[])->i32{ +auto main(const int argc,const char *const args[])->int{ if(argc>1){ std::string k; - for(i32 i{1};i2)&&(k.substr(0,2)=="-W")){ for(const auto &ref:k.substr(2,k.size())){ @@ -37,9 +37,9 @@ auto main(const i32 argc,const i8 *const args[])->i32{ } } #else -auto main()->i32{ +auto main()->int{ if(!Mod::isRunAsAdmin()){ - i8 path[MAX_PATH]; + char path[MAX_PATH]; GetModuleFileName(NULL,path,MAX_PATH); ShellExecute(NULL,"runAs",path,NULL,NULL,SW_SHOWNORMAL); return 0; diff --git a/src/mod.hpp b/src/mod.hpp index 15348208..86e53ad6 100644 --- a/src/mod.hpp +++ b/src/mod.hpp @@ -141,10 +141,10 @@ namespace Mod{ #endif struct{ struct{ - const std::vector exe,svc; + const std::vector exe,svc; }mythware; struct{ - const std::vector exe,svc; + const std::vector exe,svc; }lenovo; }rule{ { @@ -169,11 +169,11 @@ namespace Mod{ } }; struct ArgsOp final{ - const i8 key; - const std::vector &exe,&svc; + const char key; + const std::vector &exe,&svc; ArgsOp( - const i8 key, - const std::vector &exe,const std::vector &svc + const char key, + const std::vector &exe,const std::vector &svc ):key{key},exe{exe},svc{svc}{} ~ArgsOp(){} }; diff --git a/src/ui.hpp b/src/ui.hpp index b0141af2..b846d275 100644 --- a/src/ui.hpp +++ b/src/ui.hpp @@ -27,8 +27,8 @@ class UI final{ using fnCall=std::function; using sizeType=size_t; struct Item final{ - const i8 *text; - i16 colorDef,colorHighlight,colorLast; + const char *text; + short colorDef,colorHighlight,colorLast; COORD pos; fnCall fn; std::any args; @@ -36,13 +36,13 @@ class UI final{ text{},colorDef{WC_WHITE},colorHighlight{WC_BLUE}, colorLast{WC_WHITE},pos{},fn{},args{}{} Item( - const i8 *const text, - const i16 def,const i16 highlight, + const char *const text, + const short def,const short highlight, const fnCall fn,const std::any args ):text{text},colorDef{def},colorHighlight{highlight}, colorLast{WC_WHITE},pos{},fn{fn},args{args}{} ~Item(){} - auto setColor(const i8 key){ + auto setColor(const char key){ switch(key){ case 'D':{ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),colorDef); @@ -56,15 +56,15 @@ class UI final{ } } auto operator==(const COORD &refMousePos)const{ - return (pos.Y==refMousePos.Y)&&(pos.X<=refMousePos.X)&&(refMousePos.X<(pos.X+(i16)strlen(text))); + return (pos.Y==refMousePos.Y)&&(pos.X<=refMousePos.X)&&(refMousePos.X<(pos.X+(short)strlen(text))); } auto operator!=(const COORD &refMousePos)const{ return !operator==(refMousePos); } }; - i16 height,width; + short height,width; std::vector item; - auto opCursor(const i8 key){ + auto opCursor(const char key){ CONSOLE_CURSOR_INFO cursorInfo; GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursorInfo); switch(key){ @@ -78,7 +78,7 @@ class UI final{ } SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursorInfo); } - auto opAttrs(const i8 key){ + auto opAttrs(const char key){ DWORD mode; GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),&mode); switch(key){ @@ -123,15 +123,15 @@ class UI final{ std::printf("%s",std::string(width*height,' ').c_str()); setCursor({0,0}); } - auto write(const i8 *const text,const bool isEndl=false){ + auto write(const char *const text,const bool isEndl=false){ std::printf("%s",text); if(isEndl){ std::printf("\n"); } } - auto rewrite(const COORD &refPos,const i8 *const &refText){ + auto rewrite(const COORD &refPos,const char *const &refText){ setCursor({0,refPos.Y}); - for(i16 j{};j