Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 22cce319eea544ca69b71bda2b57c5fe5afd6093
Author: Andy Deng <[email protected]>
Date:   Sun Apr 17 17:31:48 2016 +0800

    rename directory Tools to tools

    Lowercase is more benifit with console users.

commit dbfb70131b502b68bc289eb1b4ba5a6945bf9342
Author: Sometimes naive <[email protected]>
Date:   Sun Apr 17 17:01:11 2016 +0800

    change directory

commit eafb82bbeacb673a871c60dd4e95246d6b5d22e6
Author: Sometimes naive <[email protected]>
Date:   Sun Apr 17 16:53:20 2016 +0800

    Add lost file.

commit 4d40dc16476b8f656af232d2b9961b8fc5e52fed
Author: Too-Naive <[email protected]>
Date:   Sun Apr 17 16:52:47 2016 +0800

    rename folder

commit 659dfa957886c7f9fc2d2c0f7cedab5f966f56c2
Author: Sometimes naive <[email protected]>
Date:   Sun Apr 17 15:30:39 2016 +0800

    Edit read me and fix #361

commit c6d813f9d1251285362415854a7e5ab8c3f5dded
Author: Sometimes naive <[email protected]>
Date:   Sun Apr 17 15:04:21 2016 +0800

    Add lost file and edit readme

commit 5cb67f405efa40ecd4bbfe0442a2f3558fe31f98
Author: Too-Naive <[email protected]>
Date:   Sun Apr 17 14:40:23 2016 +0800

    Finishing "hosts_tools" folder.
  • Loading branch information
andytimes committed Apr 17, 2016
1 parent b2310b0 commit f8c9859
Show file tree
Hide file tree
Showing 47 changed files with 90 additions and 74 deletions.
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

# Declare files that will always have CRLF line endings on checkout.
*.bat eol=crlf
hosts_tools/HostsToolforWindows/*.cpp eol=crlf
hosts_tools/HostsToolforWindows/*.hpp eol=crlf
tools/WinConsole/*.cpp eol=crlf
tools/WinConsole/*.hpp eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.gif binary
*.lib binary
4 changes: 0 additions & 4 deletions hosts_tools/HostsTool/README.MD

This file was deleted.

28 changes: 0 additions & 28 deletions hosts_tools/README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ HostsToolforMac(https://github.com/ZzzM/HostToolforMac) 是Mac平台下的
![image](https://github.com/ZzzM/hosts/blob/master/hosts_tools/HostsToolforMac/Preview/manual.gif)
####自动更新:
![image](https://github.com/ZzzM/hosts/blob/master/hosts_tools/HostsToolforMac/Preview/automatic.gif)

31 changes: 31 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Hosts Tool Pool

我们提供了一系列工具让您除了手动以 复制/粘贴 的方式部署和更新 hosts 之外,有一种方便、一键式的方式来应用我们的 hosts 。

## 支持的平台

- Microsoft Windows (`.bat` script; Qt GUI tool; console tool)
- GNU Linux (bash script)
- 跨平台的 [**Hozz**](http://ppoffice.github.io/Hozz)

## 现有的自动更新Hosts工具(粗体字为文件夹名)

- **WinGUI** : Windows环境下的GUI工具
- 使用 **C++** 构建, GUI 基于 **Qt** 。由 [@racaljk](https://github.com/racaljk) 贡献

- **WinConsole** : Windows环境下的Console工具
- 使用 **C++** 构建。由 [@Too-Naive](https://github.com/Too-Naive) 贡献

- **MacOS** : Mac 环境下的 hosts 自动部署更新应用(适用于 OS X 10.10 或以上)
- 基于 Swift 开发。由 [@ZzzM](https://github.com/ZzzM) 贡献。

- **Script**: 集合了各种系统下的脚本工具。
- [`script_tool_for_windows.bat`](http://keving.pythonanywhere.com/hosts_scripts/script_tool_for_windows.bat): Windows 环境下的 hosts 一键部署脚本,由 [@redapple0204](https://github.com/redapple0204)[@lizongzeshunshun](https://github.com/lizongzeshunshun) 贡献。以及 [@lideming](https://github.com/lideming) 提供的重要更新。

- [`script_tool_for_linux.bash`](http://keving.pythonanywhere.com/hosts_scripts/script_tool_for_linux.sh): Linux 环境下的 hosts 一键部署脚本,由 [@lstoars](https://github.com/lstoars) 贡献; [@fluviusmagnus](https://github.com/fluviusmagnus) 提供增强版本。

## 其他工具

- Hozz: 跨平台的 hosts 自动 管理/更新 工具。是 [@ppoffice](https://github.com/ppoffice) 的项目。
- [项目主页](http://ppoffice.github.io/Hozz)
- [项目Github主页](https://github.com/ppoffice/Hozz)
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# Download Executable File

Download address:[hosts_tool.exe](https://git.io/vVSwE) [Mirror address](https://yunpan.cn/cq4amgJfUZwTM)(code:b9b1)
#### Download address:
- [hosts_tool.exe](https://git.io/vVSwE)
- [Mirror address](https://yunpan.cn/cq4amgJfUZwTM)(code:b9b1)

OS type | Minimun Supported Version
--------|-------------------
WorkStation | Microsoft Windows XP Family
Server | Microsoft Windows Server 2003 Family

>If you choose `Download`, It means you agreed the MIT license(redefined).
#### Minimum Supported Operator System:
- Client : Microsoft Windows XP Family
- Server : Microsoft Windows Server 2003 Family

# Hosts Tool

这个工具可以帮助你全自动的更换 备份原来的hosts文件 所有麻烦的事情只需要打开一个程序就能搞定 并且程序还可以作为服务安装随系统启动 每次开机后都每30分钟会自动检测hosts文件的更新噢
这个工具可以帮助你全自动的更换 备份原来的hosts文件 所有麻烦的事情只需要打开一个程序就能搞定 如果你愿意,程序还可以作为服务安装随系统启动 每次开机后每隔30分钟会自动检测hosts文件的更新噢

**在此特别感谢[@qwerty258](https://githbu.com/qwerty258)为本程序提供了Visual Studio的工程文件**

## How to use?

Expand All @@ -22,15 +33,15 @@ main program file: `hosts_tool.exe`

## 注意事项

如果安装服务 程序会往`%SystemRoot%`下复制一个`hosts_tool.exe`文件用来作为服务启动的主程序
1.如果安装服务 程序会往`%SystemRoot%`下复制一个`hosts_tool.exe`文件用来作为服务启动的主程序

安装服务后 日志文件会保存在`C:\Hosts_Tool_log.log`下 您可以通过查看日志观察服务的工作状态
2.安装服务后 日志文件会保存在`C:\Hosts_Tool_log.log`下 您可以通过查看日志观察服务的工作状态

卸载服务请使用原来的`hosts_tool.exe`文件 请不要在命令行中直接执行`hosts_tool -fu`(如执行 需要手动删除`%SystemRoot%`目录下的`hoststools.exe`)
3.卸载服务请使用原来的`hosts_tool.exe`文件 请不要在命令行中直接执行`hosts_tool -fu`(如执行 需要手动删除`%SystemRoot%`目录下的`hoststools.exe`)

请间隔一段时间后清理`%SystemRoot%\system32\drivers\etc\`文件夹 (因为可能堆满了备份的文件)
4.请间隔一段时间后清理`%SystemRoot%\system32\drivers\etc\`文件夹 (因为可能堆满了备份的文件)

Bug Report: 请开新的issue并`@Too-Naive`或者发邮件给 sweheartiii[at]hotmail.com (请记得带上日志文件)
5.Bug Report: 请开新的issue并`@Too-Naive`或者发邮件给 sweheartiii[at]hotmail.com (请记得带上日志文件)

## for Developer

Expand All @@ -44,6 +55,8 @@ Bug Report: 请开新的issue并`@Too-Naive`或者发邮件给 sweheartiii[at]ho
>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
>If you use the project's source code or its derivative products (including but not limited to the executable file), it means that you have agreed to the terms of this license and comply with the terms of the license. If you do not agree to this license agreement, please do not use this project's source code and its derivatives (including but not limited to the executable file).
### Service Debug Mode :

If you want to enter debug mode, follow the steps blow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ bool Func_CheckDiff(const TCHAR *lFilePath, const TCHAR * rFilePath) throw(){
return false;
char *lBuffer = new char[BUFFER_SIZE];
char *rBuffer = new char[BUFFER_SIZE];
if (!lBuffer||!rBuffer)
if (!lBuffer||!rBuffer)
_tprintf(_T("Can't allocate memory to buffer in Func_diff\n")),abort();
do {
fread(lBuffer,sizeof(char),BUFFER_SIZE,lFile);
fread(rBuffer,sizeof(char),BUFFER_SIZE,rFile);
fread(lBuffer,sizeof(char),BUFFER_SIZE,lFile);
fread(rBuffer,sizeof(char),BUFFER_SIZE,rFile);
if (memcmp(lBuffer, rBuffer, BUFFER_SIZE)||
((!feof(lFile)&&feof(rFile))||(feof(lFile)&&!(feof(rFile))))){
delete[] lBuffer;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ struct expection{
#define PIPE_TIMEOUT 5000
#define BUFSIZE 4096

typedef struct
{
typedef struct
{
OVERLAPPED oOverlap;
HANDLE hPipeInst;
TCHAR chRequest[BUFSIZE];
Expand Down Expand Up @@ -437,7 +437,7 @@ void Func_Service_Install(bool _q){
THROWERR(_T("GetEnvironmentVariable() Error in Install Service."));
_stprintf(buf1,_T("%s\\hoststools.exe"),buf3);
_stprintf(buf2,_T("\"%s\\hoststools.exe\" -svc"),buf3);
if (request_client)
if (request_client)
_stprintf(szline,_T("%s %s"),buf2,szParameters[11]),
_tcscpy(buf2,szline),memset(szline,0,sizeof(szline)/sizeof(TCHAR));
if (!GetModuleFileName(NULL,szline,sizeof(szline)/sizeof(TCHAR)))
Expand Down Expand Up @@ -476,7 +476,7 @@ void Func_Service_Install(bool _q){
else
if (!StartService(shSvc,1,SzName))
THROWERR(_T("StartService() Failed."));
else
else
MessageBox(NULL,_T("Service started successfully"),_T("Congratulations!"),
MB_SETFOREGROUND|MB_ICONINFORMATION);
}
Expand All @@ -495,7 +495,7 @@ Please contact the application's support team for more information.\n"),
}

HANDLE ___pipeopen(){
while (1){
while (1){
if ((hdPipe = CreateFile(pipeName,GENERIC_READ|GENERIC_WRITE,0,
NULL,OPEN_EXISTING,0,NULL))!=INVALID_HANDLE_VALUE)
break;
Expand All @@ -506,7 +506,7 @@ HANDLE ___pipeopen(){
}

DWORD ___pipesentmessage(const TCHAR * szSent){
DWORD dwReserved=PIPE_READMODE_MESSAGE;
DWORD dwReserved=PIPE_READMODE_MESSAGE;
if (!SetNamedPipeHandleState(hdPipe,&dwReserved,NULL,NULL));
if (!WriteFile(hdPipe,szSent,(lstrlen(szSent)+1)*sizeof(TCHAR),&dwReserved,NULL));
return GetLastError();
Expand Down Expand Up @@ -542,7 +542,7 @@ DWORD __stdcall HostThread(LPVOID){
for (int errcunt=0;!Func_Download(hostsfile1,DownLocated)&&
!Func_Download(hostsfile,DownLocated);errcunt++,Sleep(request_client?1000:10000))
if (errcunt>1) THROWERR(_T("DownLoad hosts file Error!"));

if (!((fp=_tfopen(DownLocated,_T("r"))) && (_=_tfopen(ChangeCTLR,_T("w")))))
THROWERR(_T("Open file Error!"));
while (!feof(fp)){
Expand Down Expand Up @@ -627,18 +627,18 @@ void WINAPI Service_Control(DWORD dwControl){
}

DWORD __stdcall OpenPipeService(LPVOID){
HANDLE hConnectEvent;
OVERLAPPED oConnect;
LPPIPEINST lpPipeInst;
DWORD dwWait, cbRet;
BOOL fSuccess, fPendingIO;
HANDLE hConnectEvent;
OVERLAPPED oConnect;
LPPIPEINST lpPipeInst;
DWORD dwWait, cbRet;
BOOL fSuccess, fPendingIO;
if (!(hConnectEvent = CreateEvent(NULL,TRUE,TRUE,NULL)))
return _tprintf(_T("CreateEvent failed with %ld.\n"), GetLastError());
oConnect.hEvent = hConnectEvent;
fPendingIO = CreateAndConnectInstance(&oConnect);
while (1){
dwWait = WaitForSingleObjectEx(hConnectEvent,INFINITE,TRUE);
switch (dwWait){
switch (dwWait){
case 0:
if (fPendingIO)
if (!(fSuccess = GetOverlappedResult(hdPipe,&oConnect,&cbRet,FALSE)))
Expand All @@ -654,45 +654,45 @@ DWORD __stdcall OpenPipeService(LPVOID){
break;
default:
return printf("WaitForSingleObjectEx (%ld)\n", GetLastError());
}
}
}
}
return 0;
}
void WINAPI CompletedWriteRoutine(DWORD dwErr,DWORD cbWritten,LPOVERLAPPED lpOverLap){
}
void WINAPI CompletedWriteRoutine(DWORD dwErr,DWORD cbWritten,LPOVERLAPPED lpOverLap){
LPPIPEINST lpPipeInst;
BOOL fRead = FALSE;
lpPipeInst = (LPPIPEINST) lpOverLap;
if ((dwErr == 0) && (cbWritten == lpPipeInst->cbToWrite)){
fRead = ReadFileEx(lpPipeInst->hPipeInst,lpPipeInst->chRequest,
fRead = ReadFileEx(lpPipeInst->hPipeInst,lpPipeInst->chRequest,
BUFSIZE*sizeof(TCHAR),(LPOVERLAPPED) lpPipeInst,
(LPOVERLAPPED_COMPLETION_ROUTINE) CompletedReadRoutine);
}
if (!fRead) DisconnectAndClose(lpPipeInst);
}
}

void WINAPI CompletedReadRoutine(DWORD dwErr,DWORD cbBytesRead,LPOVERLAPPED lpOverLap){
LPPIPEINST lpPipeInst;
BOOL fWrite = FALSE;
lpPipeInst = (LPPIPEINST) lpOverLap;
if ((dwErr == 0) && (cbBytesRead != 0)){
if ((dwErr == 0) && (cbBytesRead != 0)){
GetAnswerToRequest(lpPipeInst);
fWrite = WriteFileEx(lpPipeInst->hPipeInst,lpPipeInst->chReply,
lpPipeInst->cbToWrite,(LPOVERLAPPED) lpPipeInst,
(LPOVERLAPPED_COMPLETION_ROUTINE) CompletedWriteRoutine);
}
if (!fWrite) DisconnectAndClose(lpPipeInst);
}
}

void DisconnectAndClose(LPPIPEINST lpPipeInst){
if (! DisconnectNamedPipe(lpPipeInst->hPipeInst))
printf("DisconnectNamedPipe failed with %ld.\n", GetLastError());
CloseHandle(lpPipeInst->hPipeInst);
if (lpPipeInst != NULL)
HeapFree(GetProcessHeap(),0, lpPipeInst);
}
}

BOOL CreateAndConnectInstance(LPOVERLAPPED lpoOverlap)
{
BOOL CreateAndConnectInstance(LPOVERLAPPED lpoOverlap)
{
if (!(hdPipe = CreateNamedPipe(pipeName,PIPE_ACCESS_DUPLEX |FILE_FLAG_OVERLAPPED,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,BUFSIZE*sizeof(TCHAR),BUFSIZE*sizeof(TCHAR),
Expand All @@ -701,8 +701,8 @@ BOOL CreateAndConnectInstance(LPOVERLAPPED lpoOverlap)
return ConnectToNewClient(hdPipe, lpoOverlap);
}

BOOL ConnectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo)
{
BOOL ConnectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo)
{
BOOL fConnected, fPendingIO = FALSE;
if ((fConnected = ConnectNamedPipe(hPipe, lpo)))
return 0*printf("ConnectNamedPipe failed with %ld.\n", GetLastError());
Expand All @@ -711,11 +711,11 @@ BOOL ConnectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo)
fPendingIO = TRUE;
break;
case ERROR_PIPE_CONNECTED:
if (SetEvent(lpo->hEvent))
if (SetEvent(lpo->hEvent))
break;
default:
return 0*printf("ConnectNamedPipe failed with %ld.\n", GetLastError());
}
}
return fPendingIO;
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions tools/WinGUI/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HostsTool是Windows平台下的一个简易桌面应用,它允许你通过简单的操作获取到最新的hosts更新。

![1](https://cloud.githubusercontent.com/assets/16496671/14585704/a68df23c-04b0-11e6-8282-3c9d0f05eb1a.png)
![2](https://cloud.githubusercontent.com/assets/16496671/14585705/b7f1a910-04b0-11e6-98a9-6e5274c9f4e2.png)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f8c9859

Please sign in to comment.