Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLHy0424 committed Oct 4, 2024
1 parent 5c44c4d commit e6c5376
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
3 changes: 0 additions & 3 deletions src/def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
#include<thread>
#include<functional>
#include<shlobj.h>
using i8=char;
using i16=short;
using i32=int;
#endif
#define INFO_NAME "Computer Room Control Software Nemesis"
#define INFO_VERSION "v5.8.0"
Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};i<argc;++i){
for(int i{1};i<argc;++i){
k=args[i];
if((k.size()>2)&&(k.substr(0,2)=="-W")){
for(const auto &ref:k.substr(2,k.size())){
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ namespace Mod{
#endif
struct{
struct{
const std::vector<const i8*> exe,svc;
const std::vector<const char*> exe,svc;
}mythware;
struct{
const std::vector<const i8*> exe,svc;
const std::vector<const char*> exe,svc;
}lenovo;
}rule{
{
Expand All @@ -169,11 +169,11 @@ namespace Mod{
}
};
struct ArgsOp final{
const i8 key;
const std::vector<const i8*> &exe,&svc;
const char key;
const std::vector<const char*> &exe,&svc;
ArgsOp(
const i8 key,
const std::vector<const i8*> &exe,const std::vector<const i8*> &svc
const char key,
const std::vector<const char*> &exe,const std::vector<const char*> &svc
):key{key},exe{exe},svc{svc}{}
~ArgsOp(){}
};
Expand Down
36 changes: 18 additions & 18 deletions src/ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ class UI final{
using fnCall=std::function<bool(Data)>;
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;
Item():
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);
Expand All @@ -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> item;
auto opCursor(const i8 key){
auto opCursor(const char key){
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursorInfo);
switch(key){
Expand All @@ -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){
Expand Down Expand Up @@ -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<refPos.X;++j){
for(short j{};j<refPos.X;++j){
write(" ");
}
setCursor({0,refPos.Y});
Expand Down Expand Up @@ -185,25 +185,25 @@ class UI final{
return item.size();
}
auto &add(
const i8 *const text,
const char *const text,
const fnCall fn=nullptr,const std::any args={},
const i16 colorHighlight=WC_BLUE,const i16 colorDef=WC_WHITE
const short colorHighlight=WC_BLUE,const short colorDef=WC_WHITE
){
item.emplace_back(Item(text,colorDef,(fn==nullptr)?(colorDef):(colorHighlight),fn,args));
return *this;
}
auto &insert(
const sizeType idx,const i8 *const text,
const sizeType idx,const char *const text,
const fnCall fn=nullptr,const std::any args={},
const i16 colorHighlight=WC_BLUE,const i16 colorDef=WC_WHITE
const short colorHighlight=WC_BLUE,const short colorDef=WC_WHITE
){
item.emplace(item.begin()+idx,Item(text,colorDef,(fn==nullptr)?(colorDef):(colorHighlight),fn,args));
return *this;
}
auto &edit(
const sizeType idx,const i8 *const text,
const sizeType idx,const char *const text,
const fnCall fn=nullptr,const std::any args={},
const i16 colorHighlight=WC_BLUE,const i16 colorDef=WC_WHITE
const short colorHighlight=WC_BLUE,const short colorDef=WC_WHITE
){
item.at(idx)=Item(text,colorDef,(fn==nullptr)?(colorDef):(colorHighlight),fn,args);
return *this;
Expand Down

0 comments on commit e6c5376

Please sign in to comment.