diff --git a/g++make.bat b/g++make.bat index 0c2480c..6b03741 100644 --- a/g++make.bat +++ b/g++make.bat @@ -1,4 +1,4 @@ windres tool.rc -o tmp.o -g++ -o tool.exe tool.cpp tmp.o -s -lwininet -O2 -DHOSTS_HARD_RESET +g++ -o tool.exe tool.cpp tmp.o -s -lwininet -O2 del /q tmp.o pause \ No newline at end of file diff --git a/object-runwithcode/choose.cpp b/object-runwithcode/choose.cpp index cd0d761..67b05e0 100644 --- a/object-runwithcode/choose.cpp +++ b/object-runwithcode/choose.cpp @@ -14,11 +14,13 @@ #define WIN32_LEAN_AND_MEAN +#define ExecutableFileName _T("tool.exe") + TCHAR const *szParameters[]={ _T("svc"), //for backward compatibility _T("fi"), //1 _T("fu"), //2 - _T("\x02\x03"), //3 + _T("hardreset"), //3 _T("-debug-reset"), //4 _T("\x02\x03"), //5 _T("?"), //6 @@ -35,13 +37,14 @@ TCHAR const * showNotice="\ 2. Install automanic update service\n\ 3. Uninstall automanic update service\n\ 4. Reset Hosts File\n\ - 5. Show help message\n\ - 6. Open debug mode to listen service\n\ - 7. Stop Service\n\ - 8. Start Service\n\ - 9. Open \".ini\" file\n\ + 5. Reset Hosts File(Set to Default Hosts File)\n\ + 6. Show help message\n\ + 7. Open debug mode to listen service\n\ + 8. Stop Service\n\ + 9. Start Service\n\ + 10. Open \".ini\" file\n\ "; -const int max_input_int=9; +const int max_input_int=10; TCHAR _[20]=_T(""); @@ -53,20 +56,24 @@ int _tmain(int,TCHAR const **){ _tprintf(_T("Program mode list:\n%s\n"),showNotice); _tprintf(_T("Please enter the number what you want to run:")); _tscanf(_T("%d"),&inputn); +// printf("%d\n",max_input_int); if (inputn>max_input_int || inputn<1) abort(); switch (inputn){ - case 1:ShellExecute(NULL,_T("open"),_T("tool.exe"),NULL,NULL,SW_SHOWNORMAL); + case 1:ShellExecute(NULL,_T("open"),ExecutableFileName,NULL,NULL,SW_SHOWNORMAL); exit(0); case 2:str=_T("fi");break; case 3:str=_T("fu");break; - case 4:str=_T("r");break; - case 5:str=_T("?");break; - case 6:str=szParameters[10];break; - case 7:str=szParameters[7];break; - case 8:str=szParameters[8];break; - case 9:ShellExecute(NULL,_T("open"),_T("notepad"),_T(" %windir%\\hstool.ini"),NULL,SW_SHOWDEFAULT); + case 4: + case 5:str=_T("r");break; + case 6:str=_T("?");break; + case 7:str=szParameters[10];break; + case 8:str=szParameters[7];break; + case 9:str=szParameters[8];break; + case 10:ShellExecute(NULL,_T("open"),_T("notepad"),_T(" %windir%\\hstool.ini"),NULL,SW_SHOWDEFAULT); exit(0); } - _stprintf(_,_T("-%s"),str); - ShellExecute(NULL,_T("open"),_T("tool.exe"),_,NULL,SW_SHOWNORMAL); -} \ No newline at end of file + if (inputn==5) + _stprintf(_,_T("-%s %s"),str,szParameters[3]); + else _stprintf(_,_T("-%s"),str); + ShellExecute(NULL,_T("open"),ExecutableFileName,_,NULL,SW_SHOWNORMAL); +} diff --git a/tool.cpp b/tool.cpp index 47a2c05..df84670 100644 --- a/tool.cpp +++ b/tool.cpp @@ -57,9 +57,10 @@ #define objectwebsite _T("https:\x2f\x2fgithub.com/HostsTools/Windows") //end. -#define ConsoleTitle _T("racaljk-host tool v2.1.12 Build time:Aug. 30th, '16") +#define ConsoleTitle _T("racaljk-host tool v2.1.13 Build time:Aug. 30th, '16") #define CASE(x,y) case x : y; break; +#define DEBUGCASE(x) CASE(x,___debug_point_reset(x)) #define pWait _T("\n \ There seems something wrong in download file, we will retry after 5 seconds.\n") @@ -109,11 +110,7 @@ struct expection{ } }; -#define SHOW_HELP _T("\ -------------------------------------------------------------\n\ -Hosts Tool for Windows Console by: Too-Naive\n\ -Copyright (C) 2016 @Too-Naive License:General Public License\n\ -------------------------------------------------------------\n\n\ +#define SHOW_HELP _T("%s\n\ Usage: tool [-? | -r | -fi | -fu | --debug-pipe]\n\n\ Options:\n\ -? : Show this help message.\n\ @@ -136,6 +133,12 @@ Example:\n\ * *\n\ * Powered by: @Too-Naive *\n\ **********************************************") + +#define copyrightshow _T("\ +------------------------------------------------------------\n\ +Hosts Tool for Windows Console by: Too-Naive\n\ +Copyright (C) 2016 @Too-Naive License:General Public License\n\ +------------------------------------------------------------\n") //Global variable SERVICE_STATUS_HANDLE ssh; @@ -155,7 +158,7 @@ void Func_Service_Install(bool); void Func_Service_UnInstall(bool); DWORD __stdcall NormalEntry(LPVOID); void ___debug_point_reset(int); -inline void __show_str(TCHAR const *,TCHAR const *); +inline void __show_str(TCHAR const *,TCHAR const *,TCHAR const *); void Func_ResetFile(); void ___Func_pipeCallBack(TCHAR const*); void Func_CallCopyHostsFile(); @@ -203,7 +206,7 @@ TCHAR const *szParameters[]={ _T("svc"), //for backward compatibility _T("fi"), //1 _T("fu"), //2 - _T("\x02\x03"), //3 + _T("hardreset"), //3 _T("-debug-reset"), //4 _T("\x02\x03"), //5 _T("?"), //6 @@ -223,10 +226,12 @@ int __fastcall __Check_Parameters(int argc,TCHAR const **argv){ size_t i=0; for (;_tcscmp(&(argv[1][1]),szParameters[i]) && i2) BAD_EXIT; - if (argc==3 && !_tcscmp(argv[2],szParameters[11])) request_client=1; - else if (argc==3 && _tcscmp(argv[2],szParameters[11])) BAD_EXIT; + if (argc==3 && + (!_tcscmp(argv[2],szParameters[11]) || !_tcscmp(argv[2],szParameters[3]))) + request_client=1; + else if (argc==3 && !request_client) BAD_EXIT; switch (i){ case 0: bReserved=true; return EXEC_START_SERVICE; @@ -253,12 +258,16 @@ int _tmain(int argc,TCHAR const ** argv){ CASE(EXEC_START_INSTALL_SERVICE,Func_Service_Install(true)); CASE(EXEC_START_UNINSTALL_SERVICE,Func_Service_UnInstall(true)); CASE(EXEC_START_SERVICE,StartServiceCtrlDispatcher(STE)); - CASE(EXEC_START_HELP,__show_str(SHOW_HELP,Sname)); - CASE(EXEC_DEBUG_RESET,___debug_point_reset(EXEC_DEBUG_RESET)); + CASE(EXEC_START_HELP,__show_str(SHOW_HELP,copyrightshow,Sname)); // CASE(SHOW_LICENSE,__show_str(szgpl_Raw,_pNULL_)); - CASE(DEBUG_SERVICE_STOP,___debug_point_reset(DEBUG_SERVICE_STOP)); - CASE(DEBUG_SERVICE_START,___debug_point_reset(DEBUG_SERVICE_START)); - CASE(DEBUG_SERVICE_REINSTALL,___debug_point_reset(DEBUG_SERVICE_REINSTALL)); + DEBUGCASE(EXEC_DEBUG_RESET); + DEBUGCASE(DEBUG_SERVICE_STOP); + DEBUGCASE(DEBUG_SERVICE_START); + DEBUGCASE(DEBUG_SERVICE_REINSTALL); +// CASE(EXEC_DEBUG_RESET,___debug_point_reset(EXEC_DEBUG_RESET)); +// CASE(DEBUG_SERVICE_STOP,___debug_point_reset(DEBUG_SERVICE_STOP)); +// CASE(DEBUG_SERVICE_START,___debug_point_reset(DEBUG_SERVICE_START)); +// CASE(DEBUG_SERVICE_REINSTALL,___debug_point_reset(DEBUG_SERVICE_REINSTALL)); CASE(OPEN_LISTEN,___debug_point_reset(OPEN_LISTEN)); CASE(RESET_FILE,Func_ResetFile()); default:break; @@ -304,21 +313,15 @@ namespace __Dpipe{ ss.dwWin32ExitCode=ERROR_SERVICE_SPECIFIC_ERROR; ss.dwCurrentState=SERVICE_STOPPED; SetServiceStatus(ssh,&ss); - ExitProcess(1); + ExitProcess(1); return GetLastError(); } } void Func_ResetFile(){ SYSTEMTIME st={0,0,0,0,0,0,0,0}; -#ifdef HOSTS_HARD_RESET bool chk=false; -#endif - _tprintf(_T("\ -------------------------------------------------------------\n\ -Hosts Tool for Windows Console by: Too-Naive\n\ -Copyright (C) 2016 @Too-Naive License:General Public License\n\ -------------------------------------------------------------\n")); + _tprintf(copyrightshow); if (!GetSystemDirectory(buf3,localbufsize)) _tprintf(_T(" GetSystemDirectory() Error!(GetLastError():%ld)\n\ \tCannot get system path!"),GetLastError()),abort(); @@ -330,37 +333,36 @@ Copyright (C) 2016 @Too-Naive License:General Public License\n\ else _tprintf(_T("Unable to backup file.(%ld)\n"),GetLastError()),abort(); //reset file start - FILE *fp=_tfopen(buf1, -#ifdef HOSTS_HARD_RESET - _T("w") -#else - _T("r") -#endif - ); + FILE *fp=_tfopen(buf1,request_client?_T("w"):_T("r")); if (!fp) {//,abort(); -#ifdef HOSTS_HARD_RESET - _tprintf(_T("Cannot open file!\nUsing plan B.\n")); - fp=_tfopen(ReservedFile,_T("w")); - fclose(fp); - chk=true; -#else - _tprintf(_T("Cannot open file!\n")); - abort(); -#endif - } -#ifdef HOSTS_HARD_RESET - if (chk) { - if (!CopyFile(ReservedFile,buf1,FALSE)){ - _stprintf(szline, - _T("CopyFile() Failed!(%ld)\nPlease copy the \"%s\" file to\ - \"%%systemroot%%\\drivers\\etc\\hosts\" Manually."), - GetLastError(),ReservedFile); - MessageBox(NULL,_T("Fatal Error"),szline,MB_SETFOREGROUND|MB_ICONSTOP); + if (request_client){ + _tprintf(_T("Cannot open file!\nUsing plan B.\n")); + fp=_tfopen(ReservedFile,_T("w")); + fclose(fp); + fp=_pNULL_; + chk=true; + }else{ + _tprintf(_T("Cannot open file!\n")); abort(); } } - else _ftprintf(fp,_T("%s"),szDefatult_hostsfile); -#else +if (request_client){ + if (chk) { + if (!CopyFile(ReservedFile,buf1,FALSE)){ + _stprintf(szline, + _T("CopyFile() Failed!(%ld)\nPlease copy the \"%s\" file to\ +\"%%systemroot%%\\drivers\\etc\\hosts\" Manually."), + GetLastError(),ReservedFile); + MessageBox(NULL,_T("Fatal Error"),szline,MB_SETFOREGROUND|MB_ICONSTOP); + abort(); + } + } + else _ftprintf(fp,_T("%s"),szDefatult_hostsfile); + fclose(fp); + _tprintf(_T(" Reset file successfully.\n")); + callsystempause; + ExitProcess(0); +} if (!GetEnvironmentVariable(_T("TEMP"),szline,localbufsize)) _tprintf(_T("Can't get TEMP path, using current directory.(%ld)\n"), GetLastError()), @@ -382,8 +384,6 @@ Copyright (C) 2016 @Too-Naive License:General Public License\n\ _tprintf(_T("CopyFile() Failed.(%ld)\nPlease copy the \"%s\" file to \ \"%%systemroot%%\\drivers\\etc\\hosts\" Manually."),GetLastError(),ReservedFile), abort(); -#endif - fclose(fp); //reset file end DeleteFile(ReservedFile); _tprintf(_T(" Reset file successfully.\n")); @@ -406,9 +406,10 @@ void __abrt(int){ exit(0); } -inline void __show_str(TCHAR const* st,TCHAR const * _ingore){ - if (!_ingore) _tprintf(_T("%s"),st); - else _tprintf(st,_ingore); +inline void __show_str(TCHAR const* st,TCHAR const * str2,TCHAR const * str3){ +/* if (!_ingore) _tprintf(_T("%s"),st); + else _tprintf(st,_ingore);*/ + _tprintf(st,str2,str3); callsystempause; return ; }