Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Fix #24
Browse files Browse the repository at this point in the history
* Optimization of the details
  • Loading branch information
Too-Naive committed Sep 24, 2016
1 parent 053b11f commit 92da869
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Download Executable File

[![Build status](https://ci.appveyor.com/api/projects/status/8aya86796ipmuwr2/branch/master?svg=true)](https://ci.appveyor.com/project/Too-Naive/windows/branch/master)
Last update: Sept. 17th , 2016
Last update: Sept. 24th , 2016

#### 下载地址:(v2.1.16)
#### 下载地址:(v2.1.17)

- zip Package (Include `tool.exe` and `choose.exe`)
- [点我来下载](https://git.io/vozMx)
Expand Down
32 changes: 24 additions & 8 deletions tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#define objectwebsite _T("https:\x2f\x2fgithub.com/HostsTools/Windows")
//end.

#define ConsoleTitle _T("racaljk-host tool v2.1.16 Build time:Sept. 17th, '16")
#define ConsoleTitle _T("racaljk-host tool v2.1.17 Build time:Sept. 24th, '16")

#define CASE(x,y) case x : y; break;
#define DEBUGCASE(x) CASE(x,___debug_point_reset(x))
Expand Down Expand Up @@ -146,7 +146,7 @@ SERVICE_STATUS ss;
HANDLE lphdThread[]={
INVALID_HANDLE_VALUE,INVALID_HANDLE_VALUE
};
bool request_client,bReserved,bIgnoreNewline,bIgnoreCommit;
bool request_client,bReserved,bIgnoreNewline,bIgnoreCommit,bIsNulFile=true;
WIN32_FIND_DATA wfd={0,{0,0},{0,0},{0,0},0,0,0,0,{0},{0}};
//end.

Expand All @@ -167,6 +167,7 @@ TCHAR * dotdotcheck(TCHAR *);
void Func_countBackupFile(SYSTEMTIME *);
bool Func_checkBackupFileTime(const SYSTEMTIME & , TCHAR const *);
DWORD WINAPI MonitorServiceThread(LPVOID);
inline bool Func_checkBusyTime();

//DWORD __stdcall Func_Update(LPVOID);

Expand Down Expand Up @@ -264,10 +265,6 @@ int _tmain(int argc,TCHAR const ** argv){
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;
Expand Down Expand Up @@ -701,6 +698,16 @@ void ___Func_pipeCallBack(const TCHAR * str){
void Func_CallCopyHostsFile(SYSTEMTIME & st){
FILE * fp,*_;
signal(SIGABRT,__abrt1);

//empty file check
if (!bIsNulFile){
TCHAR ch;
_=_tfopen(ReservedFile,_T("r"));
for (ch=_fgettc(_);ch==_T(' ') || ch==_T('\n') || ch==_T('\r');ch=_fgettc(_));
if (ch==EOF) bIsNulFile=true;
}
//end

if (!CopyFile(buf1,buf2,FALSE))
THROWERR(_T("CopyFile() Error on copy a backup file"));
if (!bReserved) _tprintf(_T("\tDone.\n Step3:Replace Default Hosts File..."));
Expand All @@ -712,7 +719,7 @@ void Func_CallCopyHostsFile(SYSTEMTIME & st){
_fputts(_T(""),_);
if (!(fp=_tfopen(ChangeCTLR,_T("rb"))))
throw ChangeCTLR;
_ftprintf(_,_T("\n"));
if (!bIsNulFile) _ftprintf(_,_T("\n"));
size_t readbyte=0;
while ((readbyte=fread(iobuffer,sizeof(char),localbufsize,fp)))
fwrite(iobuffer,sizeof(char),readbyte,_);
Expand Down Expand Up @@ -835,6 +842,8 @@ DWORD __stdcall NormalEntry(LPVOID){
}
//check is need ignore the new line
if (bIgnoreNewline && *szline==_T('\n')) continue;
//empty file check (if read least one line.)
bIsNulFile=false;
// print user-defined hosts to tmp file.
_fputts(szline,_);
}
Expand Down Expand Up @@ -902,7 +911,7 @@ Finish:Hosts file Not update.\n\n"));
abort();
}
}
Sleep(bReserved?(request_client?10000:(29*60000)):0);
Sleep(bReserved?(request_client?10000:(Func_checkBusyTime()?29*60000:60*60000)):0);
} while (bReserved);
return GetLastError();
}
Expand All @@ -917,6 +926,13 @@ bool Func_checkBackupFileTime(const SYSTEMTIME & st,TCHAR const * name){
return false;
}

inline bool Func_checkBusyTime(){
SYSTEMTIME st={0,0,0,0,0,0,0,0};
GetSystemTime(&st);
if (st.wHour<3 || st.wHour>7) return true;
return false;
}

void Func_countBackupFile(SYSTEMTIME * st){
HANDLE hdHandle=INVALID_HANDLE_VALUE;
DWORD __count__=0;
Expand Down

0 comments on commit 92da869

Please sign in to comment.