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

Commit 92da869

Browse files
author
Too-Naive
committed
Fix #24
* Optimization of the details
1 parent 053b11f commit 92da869

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Download Executable File
44

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

8-
#### 下载地址:(v2.1.16)
8+
#### 下载地址:(v2.1.17)
99

1010
- zip Package (Include `tool.exe` and `choose.exe`)
1111
- [点我来下载](https://git.io/vozMx)

tool.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#define objectwebsite _T("https:\x2f\x2fgithub.com/HostsTools/Windows")
5858
//end.
5959

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

6262
#define CASE(x,y) case x : y; break;
6363
#define DEBUGCASE(x) CASE(x,___debug_point_reset(x))
@@ -146,7 +146,7 @@ SERVICE_STATUS ss;
146146
HANDLE lphdThread[]={
147147
INVALID_HANDLE_VALUE,INVALID_HANDLE_VALUE
148148
};
149-
bool request_client,bReserved,bIgnoreNewline,bIgnoreCommit;
149+
bool request_client,bReserved,bIgnoreNewline,bIgnoreCommit,bIsNulFile=true;
150150
WIN32_FIND_DATA wfd={0,{0,0},{0,0},{0,0},0,0,0,0,{0},{0}};
151151
//end.
152152

@@ -167,6 +167,7 @@ TCHAR * dotdotcheck(TCHAR *);
167167
void Func_countBackupFile(SYSTEMTIME *);
168168
bool Func_checkBackupFileTime(const SYSTEMTIME & , TCHAR const *);
169169
DWORD WINAPI MonitorServiceThread(LPVOID);
170+
inline bool Func_checkBusyTime();
170171

171172
//DWORD __stdcall Func_Update(LPVOID);
172173

@@ -264,10 +265,6 @@ int _tmain(int argc,TCHAR const ** argv){
264265
DEBUGCASE(DEBUG_SERVICE_STOP);
265266
DEBUGCASE(DEBUG_SERVICE_START);
266267
DEBUGCASE(DEBUG_SERVICE_REINSTALL);
267-
// CASE(EXEC_DEBUG_RESET,___debug_point_reset(EXEC_DEBUG_RESET));
268-
// CASE(DEBUG_SERVICE_STOP,___debug_point_reset(DEBUG_SERVICE_STOP));
269-
// CASE(DEBUG_SERVICE_START,___debug_point_reset(DEBUG_SERVICE_START));
270-
// CASE(DEBUG_SERVICE_REINSTALL,___debug_point_reset(DEBUG_SERVICE_REINSTALL));
271268
CASE(OPEN_LISTEN,___debug_point_reset(OPEN_LISTEN));
272269
CASE(RESET_FILE,Func_ResetFile());
273270
default:break;
@@ -701,6 +698,16 @@ void ___Func_pipeCallBack(const TCHAR * str){
701698
void Func_CallCopyHostsFile(SYSTEMTIME & st){
702699
FILE * fp,*_;
703700
signal(SIGABRT,__abrt1);
701+
702+
//empty file check
703+
if (!bIsNulFile){
704+
TCHAR ch;
705+
_=_tfopen(ReservedFile,_T("r"));
706+
for (ch=_fgettc(_);ch==_T(' ') || ch==_T('\n') || ch==_T('\r');ch=_fgettc(_));
707+
if (ch==EOF) bIsNulFile=true;
708+
}
709+
//end
710+
704711
if (!CopyFile(buf1,buf2,FALSE))
705712
THROWERR(_T("CopyFile() Error on copy a backup file"));
706713
if (!bReserved) _tprintf(_T("\tDone.\n Step3:Replace Default Hosts File..."));
@@ -712,7 +719,7 @@ void Func_CallCopyHostsFile(SYSTEMTIME & st){
712719
_fputts(_T(""),_);
713720
if (!(fp=_tfopen(ChangeCTLR,_T("rb"))))
714721
throw ChangeCTLR;
715-
_ftprintf(_,_T("\n"));
722+
if (!bIsNulFile) _ftprintf(_,_T("\n"));
716723
size_t readbyte=0;
717724
while ((readbyte=fread(iobuffer,sizeof(char),localbufsize,fp)))
718725
fwrite(iobuffer,sizeof(char),readbyte,_);
@@ -835,6 +842,8 @@ DWORD __stdcall NormalEntry(LPVOID){
835842
}
836843
//check is need ignore the new line
837844
if (bIgnoreNewline && *szline==_T('\n')) continue;
845+
//empty file check (if read least one line.)
846+
bIsNulFile=false;
838847
// print user-defined hosts to tmp file.
839848
_fputts(szline,_);
840849
}
@@ -902,7 +911,7 @@ Finish:Hosts file Not update.\n\n"));
902911
abort();
903912
}
904913
}
905-
Sleep(bReserved?(request_client?10000:(29*60000)):0);
914+
Sleep(bReserved?(request_client?10000:(Func_checkBusyTime()?29*60000:60*60000)):0);
906915
} while (bReserved);
907916
return GetLastError();
908917
}
@@ -917,6 +926,13 @@ bool Func_checkBackupFileTime(const SYSTEMTIME & st,TCHAR const * name){
917926
return false;
918927
}
919928

929+
inline bool Func_checkBusyTime(){
930+
SYSTEMTIME st={0,0,0,0,0,0,0,0};
931+
GetSystemTime(&st);
932+
if (st.wHour<3 || st.wHour>7) return true;
933+
return false;
934+
}
935+
920936
void Func_countBackupFile(SYSTEMTIME * st){
921937
HANDLE hdHandle=INVALID_HANDLE_VALUE;
922938
DWORD __count__=0;

0 commit comments

Comments
 (0)