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

Commit

Permalink
Close #23
Browse files Browse the repository at this point in the history
* Replace NULL to _pNULL_
* Decrease warning line to 3
* Add easy function in download.hpp
  • Loading branch information
Too-Naive committed Sep 16, 2016
1 parent 4076418 commit 053b11f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 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. 11th , 2016
Last update: Sept. 17th , 2016

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

- zip Package (Include `tool.exe` and `choose.exe`)
- [点我来下载](https://git.io/vozMx)
Expand Down
2 changes: 1 addition & 1 deletion hander/default.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <tchar.h>
const TCHAR *szDefatult_hostsfile=_T("\
const TCHAR * szDefatult_hostsfile=_T("\
# Copyright (c) 1993-2009 Microsoft Corp.\n\
#\n\
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.\n\
Expand Down
33 changes: 27 additions & 6 deletions hander/download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//Code:https://raw.githubusercontent.com/Too-Naive/Tools/master/download.hpp

#pragma once

#include <windows.h>
#include <wininet.h>
#include <tchar.h>
Expand All @@ -19,6 +19,18 @@
#pragma comment(lib,"wininet.lib")
#endif

//define _pNULL_
#ifndef _pNULL_
#if (defined(__GXX_EXPERIMENTAL_CXX0X__)||\
(defined(_MSC_VER)&&(_MSC_VER>=1800)))
#define _pNULL_ nullptr
#else
#define _pNULL_ NULL
#endif
#endif
//end


#define ___userAgent TEXT("Mozilla/4.0 (compatible; Windows NT 6.1)")

bool Func_DownloadEx(const TCHAR * url,const TCHAR * file,const DWORD FileAttributes){
Expand All @@ -28,25 +40,34 @@ bool Func_DownloadEx(const TCHAR * url,const TCHAR * file,const DWORD FileAttrib
char szBuffer[dwBuffer]=""; //read buff
HANDLE hdFile=INVALID_HANDLE_VALUE; //file handle
//bug check begin
if (!(hWeb=InternetOpen(___userAgent,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0))) return false;
if (!(hRequest=InternetOpenUrl(hWeb,url,NULL,0,INTERNET_FLAG_DONT_CACHE,0))){
if (!(hWeb=InternetOpen(___userAgent,INTERNET_OPEN_TYPE_PRECONFIG,_pNULL_,_pNULL_,0))) return false;
if (!(hRequest=InternetOpenUrl(hWeb,url,_pNULL_,0,INTERNET_FLAG_DONT_CACHE,0))){
InternetCloseHandle(hWeb);
return false;
}
if ((hdFile=CreateFile(file,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FileAttributes,NULL))==INVALID_HANDLE_VALUE){
if ((hdFile=CreateFile(file,GENERIC_WRITE,0,_pNULL_,CREATE_ALWAYS,FileAttributes,_pNULL_))==INVALID_HANDLE_VALUE){
InternetCloseHandle(hWeb);
InternetCloseHandle(hRequest);
return false;
}
//end.
while (InternetReadFile(hRequest,(PVOID)szBuffer,dwBuffer,&dwReadByte) && dwReadByte)
WriteFile(hdFile,szBuffer,dwReadByte,&dwReserved,NULL);
WriteFile(hdFile,szBuffer,dwReadByte,&dwReserved,_pNULL_);
CloseHandle(hdFile);
InternetCloseHandle(hRequest);
InternetCloseHandle(hWeb);
return true;
}

inline bool __fastcall Func_Download(const TCHAR *url,const TCHAR *file){//for backward compatibility
inline bool __fastcall Func_Download(const TCHAR * url,const TCHAR * file){//for backward compatibility
return Func_DownloadEx(url,file,FILE_ATTRIBUTE_NORMAL);
}

inline bool __fastcall Func_easyDownload(const TCHAR * url){
const TCHAR * _szLocate_=_pNULL_;
for (_szLocate_=url;*++_szLocate_;);
if (*--_szLocate_=='/') return false;
for (;*(--_szLocate_)!='/';);
_szLocate_++;
return Func_Download(url,_szLocate_);
}
25 changes: 19 additions & 6 deletions hander/pipedebug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
#include <stdio.h>
#include <tchar.h>

//define _pNULL_
#ifndef _pNULL_
#if (defined(__GXX_EXPERIMENTAL_CXX0X__)||\
(defined(_MSC_VER)&&(_MSC_VER>=1800)))
#define _pNULL_ nullptr
#else
#define _pNULL_ NULL
#endif
#endif
//end

extern const TCHAR * pipeName;
HANDLE hdPipe=INVALID_HANDLE_VALUE;
extern void ___Func_pipeCallBack(TCHAR const *);
Expand Down Expand Up @@ -43,7 +54,7 @@ namespace __Dpipe{
LPPIPEINST lpPipeInst;
DWORD dwWait, cbRet;
BOOL fSuccess, fPendingIO;
if (!(hConnectEvent = CreateEvent(NULL,TRUE,TRUE,NULL)))
if (!(hConnectEvent = CreateEvent(_pNULL_,TRUE,TRUE,_pNULL_)))
return 0*_tprintf(_T("CreateEvent failed with %ld.\n"), GetLastError());
oConnect.hEvent = hConnectEvent;
fPendingIO = CreateAndConnectInstance(&oConnect);
Expand Down Expand Up @@ -96,15 +107,15 @@ namespace __Dpipe{
if (! DisconnectNamedPipe(lpPipeInst->hPipeInst))
printf("DisconnectNamedPipe failed with %ld.\n", GetLastError());
CloseHandle(lpPipeInst->hPipeInst);
if (lpPipeInst != NULL)
if (lpPipeInst != _pNULL_)
HeapFree(GetProcessHeap(),0, lpPipeInst);
}
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),
PIPE_TIMEOUT,NULL)))
PIPE_TIMEOUT,_pNULL_)))
return 0*(printf("CreateNamedPipe failed with %ld.\n", GetLastError()));
return ConnectToNewClient(hdPipe, lpoOverlap);
}
Expand Down Expand Up @@ -137,9 +148,11 @@ namespace __Dpipe{
HANDLE ___pipeopen(){
while (1){
if ((hdPipe = CreateFile(pipeName,GENERIC_READ|GENERIC_WRITE,0,
NULL,OPEN_EXISTING,0,NULL))!=INVALID_HANDLE_VALUE)
_pNULL_,OPEN_EXISTING,0,_pNULL_))!=INVALID_HANDLE_VALUE)
break;
if (GetLastError()!=ERROR_PIPE_BUSY) {
#include "ptrerr.hpp"
#pragma message("other hander file request")
Func_FastPMNTS(_T("%s Error! (%ld)\n"),_T("___pipeopen()"),GetLastError());
return INVALID_HANDLE_VALUE;
}
Expand All @@ -150,10 +163,10 @@ namespace __Dpipe{
extern DWORD ___OnError(const TCHAR *);
DWORD ___pipesendmsg(const TCHAR * szSent){
DWORD dwReserved=PIPE_READMODE_MESSAGE;
if (!SetNamedPipeHandleState(hdPipe,&dwReserved,NULL,NULL))
if (!SetNamedPipeHandleState(hdPipe,&dwReserved,_pNULL_,_pNULL_))
___OnError(_T("WriteFile"));
// Func_FastPMNTS(_T("SetNamedPipeHandleState() Error! (%ld)\n"),GetLastError());
if (!WriteFile(hdPipe,szSent,(lstrlen(szSent)+1)*sizeof(TCHAR),&dwReserved,NULL))
if (!WriteFile(hdPipe,szSent,(lstrlen(szSent)+1)*sizeof(TCHAR),&dwReserved,_pNULL_))
___OnError(_T("WriteFile"));
// Func_FastPMNTS(_T("WriteFile() Error! (%ld)\n"),GetLastError());
return GetLastError();
Expand Down
4 changes: 2 additions & 2 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.15 Build time:Sept. 11th, '16")
#define ConsoleTitle _T("racaljk-host tool v2.1.16 Build time:Sept. 17th, '16")

#define CASE(x,y) case x : y; break;
#define DEBUGCASE(x) CASE(x,___debug_point_reset(x))
Expand Down Expand Up @@ -407,7 +407,7 @@ void __abrt(int){
}

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


Expand Down

0 comments on commit 053b11f

Please sign in to comment.