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

Commit 053b11f

Browse files
author
Too-Naive
committed
Close #23
* Replace NULL to _pNULL_ * Decrease warning line to 3 * Add easy function in download.hpp
1 parent 4076418 commit 053b11f

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

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. 11th , 2016
6+
Last update: Sept. 17th , 2016
77

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

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

hander/default.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include <tchar.h>
3-
const TCHAR *szDefatult_hostsfile=_T("\
3+
const TCHAR * szDefatult_hostsfile=_T("\
44
# Copyright (c) 1993-2009 Microsoft Corp.\n\
55
#\n\
66
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.\n\

hander/download.hpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//Code:https://raw.githubusercontent.com/Too-Naive/Tools/master/download.hpp
99

1010
#pragma once
11-
11+
1212
#include <windows.h>
1313
#include <wininet.h>
1414
#include <tchar.h>
@@ -19,6 +19,18 @@
1919
#pragma comment(lib,"wininet.lib")
2020
#endif
2121

22+
//define _pNULL_
23+
#ifndef _pNULL_
24+
#if (defined(__GXX_EXPERIMENTAL_CXX0X__)||\
25+
(defined(_MSC_VER)&&(_MSC_VER>=1800)))
26+
#define _pNULL_ nullptr
27+
#else
28+
#define _pNULL_ NULL
29+
#endif
30+
#endif
31+
//end
32+
33+
2234
#define ___userAgent TEXT("Mozilla/4.0 (compatible; Windows NT 6.1)")
2335

2436
bool Func_DownloadEx(const TCHAR * url,const TCHAR * file,const DWORD FileAttributes){
@@ -28,25 +40,34 @@ bool Func_DownloadEx(const TCHAR * url,const TCHAR * file,const DWORD FileAttrib
2840
char szBuffer[dwBuffer]=""; //read buff
2941
HANDLE hdFile=INVALID_HANDLE_VALUE; //file handle
3042
//bug check begin
31-
if (!(hWeb=InternetOpen(___userAgent,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0))) return false;
32-
if (!(hRequest=InternetOpenUrl(hWeb,url,NULL,0,INTERNET_FLAG_DONT_CACHE,0))){
43+
if (!(hWeb=InternetOpen(___userAgent,INTERNET_OPEN_TYPE_PRECONFIG,_pNULL_,_pNULL_,0))) return false;
44+
if (!(hRequest=InternetOpenUrl(hWeb,url,_pNULL_,0,INTERNET_FLAG_DONT_CACHE,0))){
3345
InternetCloseHandle(hWeb);
3446
return false;
3547
}
36-
if ((hdFile=CreateFile(file,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FileAttributes,NULL))==INVALID_HANDLE_VALUE){
48+
if ((hdFile=CreateFile(file,GENERIC_WRITE,0,_pNULL_,CREATE_ALWAYS,FileAttributes,_pNULL_))==INVALID_HANDLE_VALUE){
3749
InternetCloseHandle(hWeb);
3850
InternetCloseHandle(hRequest);
3951
return false;
4052
}
4153
//end.
4254
while (InternetReadFile(hRequest,(PVOID)szBuffer,dwBuffer,&dwReadByte) && dwReadByte)
43-
WriteFile(hdFile,szBuffer,dwReadByte,&dwReserved,NULL);
55+
WriteFile(hdFile,szBuffer,dwReadByte,&dwReserved,_pNULL_);
4456
CloseHandle(hdFile);
4557
InternetCloseHandle(hRequest);
4658
InternetCloseHandle(hWeb);
4759
return true;
4860
}
4961

50-
inline bool __fastcall Func_Download(const TCHAR *url,const TCHAR *file){//for backward compatibility
62+
inline bool __fastcall Func_Download(const TCHAR * url,const TCHAR * file){//for backward compatibility
5163
return Func_DownloadEx(url,file,FILE_ATTRIBUTE_NORMAL);
5264
}
65+
66+
inline bool __fastcall Func_easyDownload(const TCHAR * url){
67+
const TCHAR * _szLocate_=_pNULL_;
68+
for (_szLocate_=url;*++_szLocate_;);
69+
if (*--_szLocate_=='/') return false;
70+
for (;*(--_szLocate_)!='/';);
71+
_szLocate_++;
72+
return Func_Download(url,_szLocate_);
73+
}

hander/pipedebug.hpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
#include <stdio.h>
1010
#include <tchar.h>
1111

12+
//define _pNULL_
13+
#ifndef _pNULL_
14+
#if (defined(__GXX_EXPERIMENTAL_CXX0X__)||\
15+
(defined(_MSC_VER)&&(_MSC_VER>=1800)))
16+
#define _pNULL_ nullptr
17+
#else
18+
#define _pNULL_ NULL
19+
#endif
20+
#endif
21+
//end
22+
1223
extern const TCHAR * pipeName;
1324
HANDLE hdPipe=INVALID_HANDLE_VALUE;
1425
extern void ___Func_pipeCallBack(TCHAR const *);
@@ -43,7 +54,7 @@ namespace __Dpipe{
4354
LPPIPEINST lpPipeInst;
4455
DWORD dwWait, cbRet;
4556
BOOL fSuccess, fPendingIO;
46-
if (!(hConnectEvent = CreateEvent(NULL,TRUE,TRUE,NULL)))
57+
if (!(hConnectEvent = CreateEvent(_pNULL_,TRUE,TRUE,_pNULL_)))
4758
return 0*_tprintf(_T("CreateEvent failed with %ld.\n"), GetLastError());
4859
oConnect.hEvent = hConnectEvent;
4960
fPendingIO = CreateAndConnectInstance(&oConnect);
@@ -96,15 +107,15 @@ namespace __Dpipe{
96107
if (! DisconnectNamedPipe(lpPipeInst->hPipeInst))
97108
printf("DisconnectNamedPipe failed with %ld.\n", GetLastError());
98109
CloseHandle(lpPipeInst->hPipeInst);
99-
if (lpPipeInst != NULL)
110+
if (lpPipeInst != _pNULL_)
100111
HeapFree(GetProcessHeap(),0, lpPipeInst);
101112
}
102113
BOOL CreateAndConnectInstance(LPOVERLAPPED lpoOverlap)
103114
{
104115
if (!(hdPipe = CreateNamedPipe(pipeName,PIPE_ACCESS_DUPLEX |FILE_FLAG_OVERLAPPED,
105116
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
106117
PIPE_UNLIMITED_INSTANCES,BUFSIZE*sizeof(TCHAR),BUFSIZE*sizeof(TCHAR),
107-
PIPE_TIMEOUT,NULL)))
118+
PIPE_TIMEOUT,_pNULL_)))
108119
return 0*(printf("CreateNamedPipe failed with %ld.\n", GetLastError()));
109120
return ConnectToNewClient(hdPipe, lpoOverlap);
110121
}
@@ -137,9 +148,11 @@ namespace __Dpipe{
137148
HANDLE ___pipeopen(){
138149
while (1){
139150
if ((hdPipe = CreateFile(pipeName,GENERIC_READ|GENERIC_WRITE,0,
140-
NULL,OPEN_EXISTING,0,NULL))!=INVALID_HANDLE_VALUE)
151+
_pNULL_,OPEN_EXISTING,0,_pNULL_))!=INVALID_HANDLE_VALUE)
141152
break;
142153
if (GetLastError()!=ERROR_PIPE_BUSY) {
154+
#include "ptrerr.hpp"
155+
#pragma message("other hander file request")
143156
Func_FastPMNTS(_T("%s Error! (%ld)\n"),_T("___pipeopen()"),GetLastError());
144157
return INVALID_HANDLE_VALUE;
145158
}
@@ -150,10 +163,10 @@ namespace __Dpipe{
150163
extern DWORD ___OnError(const TCHAR *);
151164
DWORD ___pipesendmsg(const TCHAR * szSent){
152165
DWORD dwReserved=PIPE_READMODE_MESSAGE;
153-
if (!SetNamedPipeHandleState(hdPipe,&dwReserved,NULL,NULL))
166+
if (!SetNamedPipeHandleState(hdPipe,&dwReserved,_pNULL_,_pNULL_))
154167
___OnError(_T("WriteFile"));
155168
// Func_FastPMNTS(_T("SetNamedPipeHandleState() Error! (%ld)\n"),GetLastError());
156-
if (!WriteFile(hdPipe,szSent,(lstrlen(szSent)+1)*sizeof(TCHAR),&dwReserved,NULL))
169+
if (!WriteFile(hdPipe,szSent,(lstrlen(szSent)+1)*sizeof(TCHAR),&dwReserved,_pNULL_))
157170
___OnError(_T("WriteFile"));
158171
// Func_FastPMNTS(_T("WriteFile() Error! (%ld)\n"),GetLastError());
159172
return GetLastError();

tool.cpp

Lines changed: 2 additions & 2 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.15 Build time:Sept. 11th, '16")
60+
#define ConsoleTitle _T("racaljk-host tool v2.1.16 Build time:Sept. 17th, '16")
6161

6262
#define CASE(x,y) case x : y; break;
6363
#define DEBUGCASE(x) CASE(x,___debug_point_reset(x))
@@ -407,7 +407,7 @@ void __abrt(int){
407407
}
408408

409409
void __abrt1(int){
410-
for (int i=70;i--;_tprintf(_T("Please check anti-virus software then open this program again.\n")));
410+
for (int i=3;i--;_tprintf(_T("Please check anti-virus software then open this program again.\n")));
411411
}
412412

413413

0 commit comments

Comments
 (0)