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

Commit

Permalink
Merge pull request #15 from HostsTools/n
Browse files Browse the repository at this point in the history
v2.1.5 Release
* Add uninstall service direct by using service execute file.
* Change working directory to %TEMP%.
* Add customize set is program should ignore empty line and commits.
 * File is located at %windir%.
* Temporary file will reserved in %TEMP%
* Add choose.exe, easy to run main executable file
* Add easy to uninstall service options
* Del old grammar
  • Loading branch information
+1s authored Jun 17, 2016
2 parents 8cc5bb3 + e2109ce commit 05ccddb
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 94 deletions.
49 changes: 11 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# 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: May 31th , 2016
Last update: Jun. 17th , 2016

#### 下载地址:(v2.1.5p)
- [点我来下载](https://git.io/vwsqL)
- [如果上面那个不行的话点我](https://yunpan.cn/cPseSVaAVwMBL)(code:5c40)
#### 下载地址:(v2.1.5)

- zip Package (Include `tool.exe` and `choose.exe`)
- [点我来下载](https://git.io/vozMx)
- [如果上面那个不行的话点我](https://yunpan.cn/cR6spD6qp89N4)(code:fdf5)

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).
# 9天后才会继续推出新的更新
目前`build passing` , 如有其他疑问请在issue中提出问题
最新的版本更新是 现在程序不会忽略`#`开头的注释语句
>If you choose `Download`, It means you agreed the General public license.
# Hosts Tool

Expand All @@ -38,11 +36,12 @@ Server | Microsoft Windows Server 2003 Family

程序不会将第一行过滤掉,而会从`# Copyright (c) 2014-2016, racaljk.`开始改写hosts文件。

如需忽略空行以及注释 请使用`choose.exe`打开`.ini`文件修改`false``true`

## 警告

1. **请不要删除`# Copyright (c) 2014-2016, racaljk.`(作为程序的识别位点) 否则 有可能发生不可预料的后果**
2. **如果先前没有使用本项目hosts文件 而使用了其他项目的hosts文件的 请重置hosts文件(具体方法看下方使用说明)后 再使用本程序**
3. ~~**(在自定义的hosts中)程序会抛掉所有的注释`#`开头的语句**~~(功能已经弃用 将会在2.1.5的正式版中启用新的选项)

## How to use?

Expand All @@ -51,43 +50,17 @@ Server | Microsoft Windows Server 2003 Family
main program file: `tool.exe`

- 无参数运行`tool.exe` 用来更新hosts文件 如有更新 程序会备份原有的hosts文件
- 带参数 `-fi` 运行 `tool.exe` 安装一个名为`racaljk-hoststool`的服务
- 带参数 `-fu` 运行 `tool.exe` 卸载已经安装的`racaljk-hoststool`服务
- 带参数 `-r` 运行 `tool.exe` 来重置hosts文件
- 带参数 `-?` 运行 `tool.exe` 来获得更多的使用方法
- 运行`choose.exe` 来选择更多的运行选项

## 注意事项

1. 如果安装服务 程序会往`%SystemRoot%`下复制一个`tool.exe`文件用来作为服务启动的主程序
2. 安装服务后 日志文件会保存在`C:\Hosts_Tool_log.log`下 您可以通过查看日志观察服务的工作状态
3. 卸载服务请使用原来的`tool.exe`文件 请不要在命令行中直接执行`hoststools -fu`(如执行 需要手动删除`%SystemRoot%`目录下的`hoststools.exe`)
7. 本程序一切有更改hosts文件的行为前都会先备份hosts文件。
4. 请间隔一段时间后清理`%SystemRoot%\system32\drivers\etc\`文件夹 (因为可能堆满了备份的文件)
5. 如有任何疑问或bug反馈,请开新的issue或者发邮件到 sometimes.naive[at]hotmail.com (如是服务问题请附上日志文件)

## for Developer

### Code license:
## Code license:

General public license version 3

### Service Debug Mode :

If you want to enter debug mode, follow the steps blow.

1. Open the console.
2. Change the working directory where is the `tool.exe` position.
3. Input `tool --debug-pipe` and press enter.
4. Now you can see the current working status of service.
5. Press **Ctrl+C** to Exit debug mode.
6. Exit debug mode will cause service uninstall.

**WARNING: IN DEBUG MODE, DO NOT CLOSE THE CONSOLE DIRECT**

*Notice:In debug mode, service run cycle is very sort*

Fixed: if exit program unexpectally, service will run with system start.(and then sent unexpect data)

### How to compile?

Please see the [documents.md](https://github.com/HostsTools/Windows/blob/master/documents.md)
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

17 changes: 17 additions & 0 deletions documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ Function name | Description
6. Delete temp file


## Service Debug Mode :

If you want to enter debug mode, follow the steps blow.

1. Open the console.
2. Change the working directory where is the `tool.exe` position.
3. Input `tool --debug-pipe` and press enter.
4. Now you can see the current working status of service.
5. Press **Ctrl+C** to Exit debug mode.
6. Exit debug mode will cause service uninstall.

**WARNING: IN DEBUG MODE, DO NOT CLOSE THE CONSOLE DIRECT**

*Notice:In debug mode, service run cycle is very sort*

Fixed: if exit program unexpectally, service will run with system start.(and then sent unexpect data)

## Hosts Backup file(Windows 7+)

```
Expand Down
4 changes: 3 additions & 1 deletion hander/pipedebug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

extern const TCHAR * pipeName;
HANDLE hdPipe=INVALID_HANDLE_VALUE;
extern void ___Func_pipeCallBack(TCHAR const *);
namespace __Dpipe{
//for pipe debug
const DWORD PIPE_TIMEOUT=5000;
Expand Down Expand Up @@ -126,7 +127,8 @@ namespace __Dpipe{
}
inline void GetAnswerToRequest(LPPIPEINST pipe)
{
_tprintf( TEXT("%s"), pipe->chRequest);
___Func_pipeCallBack(pipe->chRequest);
// _tprintf( TEXT("%s"), pipe->chRequest);
//reserved:
/* _tprintf( TEXT("[%p] %s"), pipe->hPipeInst, pipe->chRequest);
lstrcpyn( pipe->chReply, TEXT("") ,BUFSIZE);
Expand Down
8 changes: 4 additions & 4 deletions hander/ptrerr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const TCHAR * sz__ErrorFileName__=_ptrresev_NULL_;
const TCHAR * sz__ErrorFileStream__=_ptrresev_NULL_;

FILE * Func_SetErrorFile(const TCHAR*, const TCHAR*);
inline void * __fastcall ___Func_Close_File_Stream(FILE *) throw();
inline int __fastcall ___Func_PrintErrorTimeToFileStream(FILE *) throw();
inline void * __fastcall ___Func_Close_File_Stream(FILE *);
inline int __fastcall ___Func_PrintErrorTimeToFileStream(FILE *);
inline void * ___Func__Check_File_Set(void);

#define __BEGIN__ Func_SetErrorFileEx(sz__ErrorFileName__,sz__ErrorFileStream__)
Expand Down Expand Up @@ -220,7 +220,7 @@ inline void * ___Func__Check_File_Set(void){
return _ptrresev_NULL_;
}

inline void * __fastcall ___Func_Close_File_Stream(FILE * ___ptr_fp) throw(){
inline void * __fastcall ___Func_Close_File_Stream(FILE * ___ptr_fp){
if (!___ptr_fp && ptr_ErrorFileStream) fclose(ptr_ErrorFileStream);
else fclose(___ptr_fp);
return _ptrresev_NULL_;
Expand All @@ -240,7 +240,7 @@ FILE * Func_SetErrorFile(const TCHAR * _FileName_,const TCHAR * _StreamStatus){
return ptr_ErrorFileStream;
}

inline int __fastcall ___Func_PrintErrorTimeToFileStream(FILE * ___ptr_fp) throw(){
inline int __fastcall ___Func_PrintErrorTimeToFileStream(FILE * ___ptr_fp){
SYSTEMTIME _st_={0,0,0,0,0,0,0,0};
GetLocalTime(&_st_);
return _ftprintf(___ptr_fp,_T("%04d/%02d/%02d %02d:%02d:%02d "),_st_.wYear,_st_.wMonth,
Expand Down
88 changes: 71 additions & 17 deletions object-runwithcode/choose.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,71 @@
/*
* This source code was published under GPL v3
*
* Copyright (C) 2016 Too-Naive E-mail:[email protected]
*
*/

#include <stdio.h>
#include <windows.h>
#include <tchar.h>
#define WIN32_LEAN_AND_MEAN


int _tmain(int,TCHAR const **){
_tscanf(_T("%d"));
}

/*
* This source code was published under GPL v3
*
* Copyright (C) 2016 Too-Naive E-mail:[email protected]
*
*/


#include <stdio.h>
#include <string.h>
#include <tchar.h>
#include <stdlib.h>
#include <windows.h>

#define WIN32_LEAN_AND_MEAN

TCHAR const *szParameters[]={
_T("svc"), //for backward compatibility
_T("fi"), //1
_T("fu"), //2
_T("\x02\x03"), //3
_T("-debug-reset"), //4
_T("\x02\x03"), //5
_T("?"), //6
_T("-debug-stop"), //7
_T("-debug-start"), //8
_T("-debug-reiu"), //9
_T("-debug-pipe"), //10
_T("--pipe"), //11
_T("r") //12
};

TCHAR const * showNotice="\
1. Run normaly\n\
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\
";
const int max_input_int=8;


TCHAR _[20]=_T("");

int _tmain(int,TCHAR const **){
SetConsoleTitle(_T("Run Execute"));
int inputn;
const TCHAR * str=_T("");
_tprintf(_T("Program mode list:\n%s\n"),showNotice);
_tprintf(_T("Please enter the number what you want to run:"));
_tscanf(_T("%d"),&inputn);
if (inputn>max_input_int || inputn<1) abort();
switch (inputn){
case 1:str=_T("");break;
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);
exit(0);
}
_stprintf(_,_T("-%s"),str);
ShellExecute(NULL,_T("open"),_T("tool.exe"),_,NULL,SW_SHOWNORMAL);
}
Loading

0 comments on commit 05ccddb

Please sign in to comment.