반응형
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 배열
- SetMouseDelay
- DetectHiddenWindows
- 식의 설명
- if
- SetControlDelay
- SetEnv
- ControlGetText
- API
- EnvAdd
- SetKeyDelay
- EnvMult
- Blocks
- IF (식)
- Threads
- ControlSend
- Menu
- StringGetPos
- EnvSet
- autohotkey
- MouseClick
- IfInString
- EnvDiv
- 식
- Var:=식
- EnvSub
- SetTitleMatchMode
- 함수
- IfWinExist
- if(식)
Archives
- Today
- Total
ㄴrㅎnㅂrㄹrㄱi
DllCall: Basic FTP Functions 본문
반응형
-
/*
-
http://msdn.microsoft.com/library/en-us/wininet/wininet/ftp_sessions.asp
-
http://msdn.microsoft.com/library/en-us/wininet/wininet/internetopen.asp
-
http://msdn.microsoft.com/library/en-us/wininet/wininet/internetconnect.asp
-
*/
-
-
FtpCreateDirectory(DirName) {
-
global ic_hInternet
-
r := DllCall("wininetFtpCreateDirectoryA", "uint", ic_hInternet, "str", DirName)
-
If (ErrorLevel != 0 or r = 0)
-
return 0
-
else
-
return 1
-
}
-
-
FtpRemoveDirectory(DirName) {
-
global ic_hInternet
-
r := DllCall("wininetFtpRemoveDirectoryA", "uint", ic_hInternet, "str", DirName)
-
If (ErrorLevel != 0 or r = 0)
-
return 0
-
else
-
return 1
-
}
-
-
FtpSetCurrentDirectory(DirName) {
-
global ic_hInternet
-
r := DllCall("wininetFtpSetCurrentDirectoryA", "uint", ic_hInternet, "str", DirName)
-
If (ErrorLevel != 0 or r = 0)
-
return 0
-
else
-
return 1
-
}
-
-
FtpPutFile(LocalFile, NewRemoteFile="", Flags=0) {
-
;Flags:
-
;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
-
;FTP_TRANSFER_TYPE_ASCII = 1
-
;FTP_TRANSFER_TYPE_BINARY = 2
-
If NewRemoteFile=
-
NewRemoteFile := LocalFile
-
global ic_hInternet
-
r := DllCall("wininetFtpPutFileA"
-
, "uint", ic_hInternet
-
, "str", LocalFile
-
, "str", NewRemoteFile
-
, "uint", Flags
-
, "uint", 0) ;dwContext
-
If (ErrorLevel != 0 or r = 0)
-
return 0
-
else
-
return 1
-
}
-
-
FtpGetFile(RemoteFile, NewFile="", Flags=0) {
-
;Flags:
-
;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
-
;FTP_TRANSFER_TYPE_ASCII = 1
-
;FTP_TRANSFER_TYPE_BINARY = 2
-
If NewFile=
-
NewFile := RemoteFile
-
global ic_hInternet
-
r := DllCall("wininetFtpGetFileA"
-
, "uint", ic_hInternet
-
, "str", RemoteFile
-
, "str", NewFile
-
, "int", 1 ;do not overwrite existing files
-
, "uint", 0 ;dwFlagsAndAttributes
-
, "uint", Flags
-
, "uint", 0) ;dwContext
-
If (ErrorLevel != 0 or r = 0)
-
return 0
-
else
-
return 1
-
}
-
-
FtpGetFileSize(FileName, Flags=0) {
-
;Flags:
-
;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
-
;FTP_TRANSFER_TYPE_ASCII = 1
-
;FTP_TRANSFER_TYPE_BINARY = 2
-
global ic_hInternet
-
fof_hInternet := DllCall("wininetFtpOpenFileA"
-
, "uint", ic_hInternet
-
, "str", FileName
-
, "uint", 0x80000000 ;dwAccess: GENERIC_READ
-
, "uint", Flags
-
, "uint", 0) ;dwContext
-
If (ErrorLevel != 0 or fof_hInternet = 0)
-
return -1
-
-
FileSize := DllCall("wininetFtpGetFileSize", "uint", fof_hInternet, "uint", 0)
-
DllCall("wininetInternetCloseHandle", "UInt", fof_hInternet)
-
return, FileSize
-
}
-
-
-
FtpDeleteFile(FileName) {
-
global ic_hInternet
-
r := DllCall("wininetFtpDeleteFileA", "uint", ic_hInternet, "str", FileName)
-
If (ErrorLevel != 0 or r = 0)
-
return 0
-
else
-
return 1
-
}
-
-
FtpRenameFile(Existing, New) {
-
global ic_hInternet
-
r := DllCall("wininetFtpRenameFileA", "uint", ic_hInternet, "str", Existing, "str", New)
-
If (ErrorLevel != 0 or r = 0)
-
return 0
-
else
-
return 1
-
}
-
-
FtpOpen(Server, Port=21, Username=0, Password=0 ,Proxy="", ProxyBypass="") {
-
IfEqual, Username, 0, SetEnv, Username, anonymous
-
IfEqual, Password, 0, SetEnv, Password, anonymous
-
-
If (Proxy != "")
-
AccessType=3
-
Else
-
AccessType=1
-
;#define INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration
-
;#define INTERNET_OPEN_TYPE_DIRECT 1 // direct to net
-
;#define INTERNET_OPEN_TYPE_PROXY 3 // via named proxy
-
;#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS
-
-
global ic_hInternet, io_hInternet
-
hModule := DllCall("LoadLibrary", "str", "wininet.dll")
-
-
io_hInternet := DllCall("wininetInternetOpenA"
-
, "str", A_ScriptName ;lpszAgent
-
, "UInt", AccessType
-
, "str", Proxy
-
, "str", ProxyBypass
-
, "UInt", 0) ;dwFlags
-
-
If (ErrorLevel != 0 or io_hInternet = 0) {
-
FtpClose()
-
return 0
-
}
-
-
ic_hInternet := DllCall("wininetInternetConnectA"
-
, "uint", io_hInternet
-
, "str", Server
-
, "uint", Port
-
, "str", Username
-
, "str", Password
-
, "uint" , 1 ;dwService (INTERNET_SERVICE_FTP = 1)
-
, "uint", 0 ;dwFlags
-
, "uint", 0) ;dwContext
-
-
If (ErrorLevel != 0 or ic_hInternet = 0)
-
return 0
-
else
-
return 1
-
}
-
-
FtpClose() {
-
global ic_hInternet, io_hInternet
-
DllCall("wininetInternetCloseHandle", "UInt", ic_hInternet)
-
DllCall("wininetInternetCloseHandle", "UInt", io_hInternet)
-
DllCall("FreeLibrary", "UInt", hModule)
-
}
-
-
; sample values
-
FtpHost = autohotkey.net
-
FtpPort = 21
-
FtpUsername = AhkH4x0r
-
FtpPassword = Ahk1337
-
localFile = C:FtpTest.txt
-
remoteFile = test/FtpTest.txt
-
-
; establish connection to FTP server
-
connect:
-
FtpConnection := FtpOpen(FtpHost, FtpPort, FtpUsername, FtpPassword)
-
If (FtpConnection != 1)
-
{
-
MsgBox, Error connecting to FTP server.
-
GoSub, quit
-
}
-
Return
-
-
; upload file
-
uploadFile:
-
; establish connection to FTP server
-
GoSub, connect
-
; store file on FTP server
-
fileTransfer := FtpPutFile(localFile, remoteFile)
-
If (fileTransfer != 1)
-
{
-
MsgBox, Error uploading file.
-
GoSub, quit
-
}
-
; close connection
-
FtpClose()
-
; confirmation message
-
MsgBox, Upload complete.
-
; terminate script
-
GoSub, quit
-
Return
-
-
; download file
-
downloadFile:
-
; establish connection to FTP server
-
GoSub, connect
-
; retrieve file from FTP server
-
fileTransfer := FtpGetFile(remoteFile, localFile)
-
If (fileTransfer != 1)
-
{
-
MsgBox, Error downloading file.
-
GoSub, quit
-
}
-
; close connection
-
FtpClose()
-
; confirmation message
-
MsgBox, Download complete.
-
; terminate script
-
GoSub, quit
-
Return
-
; ----------------------------------------------
-
; ----------------------------------------------
-
Txt2Hex(Txt) { ;v1.0 by Elevator_Hazard
-
format := A_FormatInteger
-
StringSplit, TxtArray, Txt
-
loop, %TxtArray0%
-
{
-
CurrentTxt := TxtArray%A_Index%
-
blah := Asc(CurrentTxt)
-
SetFormat, Integer, Hex
-
Hex := Asc(CurrentTxt)
-
SetFormat, Integer, Decimal
-
StringReplace, Hex, Hex, 0x,,All
-
If StrLen(Hex) = 1
-
{
-
Hex := Hex . "0"
-
}
-
Hex%A_Index% := Hex
-
}
-
Hex=
-
Loop, %TxtArray0%
-
{
-
Hex := Hex . Hex%A_Index%
-
}
-
SetFormat, Integer, %Format%
-
return %Hex%
-
}
-
-
Hex2Txt(Hex) { ;v1.0 by Elevator_Hazard
-
format := A_FormatInteger
-
go=1
-
Txt=
-
HexLen := StrLen(Hex)
-
Loop, %HexLen%
-
{
-
If go=1
-
{
-
go=0
-
HexSet := "0x" . SubStr(Hex, A_Index, 2)
-
SetFormat, Integer, Decimal
-
HexSet += 0
-
Txt := Txt . Chr(HexSet)
-
}
-
else
-
{
-
go=1
-
}
-
}
-
SetFormat, Integer, %Format%
-
return %Txt%
-
}
-
; ########################
-
; ##### Auto-Exec ########
-
; ########################
-
URL=http://clangs.org/index.php?showtopic=1373
-
version=1.0
-
URLDownloadToFile, http://www.autohotkey.net/~Elevator_Hazard/HexiWizardUpdate.txt, %A_WorkingDir%CheckForUpdates.txt
-
FileReadLine, URLVersion, %A_WorkingDir%CheckForUpdates.txt, 1
-
If URLVersion=%version%
-
{
-
}
-
Else
-
{
-
FileRead, UpdateInfo, %A_WorkingDir%CheckForUpdates.txt
-
Gosub, UpdateWin
-
}
-
-
IniRead, HasBeenUsed, %A_WorkingDir%Config.ini, general, hasbeenused
-
if HasBeenUsed = 1
-
{
-
-
}
-
else
-
{
-
IniWrite, 1, %A_WorkingDir%Config.ini, general, hasbeenused
-
MsgBox, HexiWizard is now running`, To capture a pixels color under the mouse`,press Ctrl+Shift+/`,`n to choose a custom color`, press the "Choose Color" Button.
-
}
-
mini = 0
-
SLIDE_DUR = 750
-
FADE_DUR = 1000
-
sampint= 0
-
title = HexiWizard
-
FADE_IN = 0xa0000
-
FADE_OUT = 0x90000
-
ROLL_TOP_TO_BOTTOM = 0x20004
-
ROLL_BOTTOM_TO_TOP = 0x20008
-
SLIDE_TOP_TO_BOTTOM= 0x40004
-
SLIDE_BOTTOM_TO_TOP= 0x40008
-
-
;GUI_HEIGHT = 351
-
GUI_HEIGHT = 380
-
GUI_WIDTH = 294
-
GUI_START_X := A_ScreenWidth - GUI_Width
-
GUI_START_Y := A_ScreenHeight - GUI_Height
-
GUI_MINI_Y := A_ScreenHeight - 50
-
gui, +Toolwindow -Caption +Border +LastFound +AlwaysOnTop
-
gui, add, text, gMini vMiniText x264 y3 w17 h17 +Center +Border, __
-
gui, add, text, gExit x279 y3 w17 h17 +Center +Border, X
-
Gui, Add, GroupBox, x16 y10 w230 h80 +Center, Choose Color
-
Gui, Add, Button, x76 y40 w100 h30 gChooseColor, Choose Color
-
Gui, Add, GroupBox, x16 y90 w230 h80 +Center, Regular Hex Code
-
Gui, Add, Edit, x86 y140 w90 h20 ReadOnly vRegHex,
-
Gui, Add, GroupBox, x16 y170 w230 h80 +Center, HTML Hex Code
-
Gui, Add, Edit, x86 y220 w90 h20 ReadOnly vHTMLHex,
-
Gui, Add, GroupBox, x16 y250 w230 h80 +Center, Warcraft 3 Hex Code
-
Gui, Add, Edit, x86 y300 w90 h20 ReadOnly vWc3Hex,
-
Gui, Add, Progress, x256 y20 w30 h310 vSampColor c%Color%, 100
-
;Gui, Add, Picture, x256 y20 w30 h310 vSampColor ,%A_WorkingDir%Color.bmp
-
; Generated using SmartGUI Creator 4.0
-
hWnd := WinExist()
-
Gui, Show, x%GUI_START_X% y%GUI_START_Y% h%GUI_HEIGHT% w%GUI_WIDTH% Hide, %title%
-
AnimateWindow(hWnd,SLIDE_DUR,SLIDE_BOTTOM_TO_TOP)
-
Return
-
-
; ########################
-
; ##### Subroutines ######
-
; ########################
-
-
URL:
-
run, %URL%
-
return
-
-
2GuiClose:
-
Gui, 2: destroy
-
return
-
-
UpdateWin:
-
Gui,2: +AlwaysOnTop
-
Gui,2: Add, Text, x153 y10 w90 h20 , Update Available!
-
Gui,2: Add, GroupBox, x16 y30 w360 h310 ,
-
Gui,2: Add, Text, x26 y50 w340 h280 , %UpdateInfo%
-
Gui,2: Add, GroupBox, x16 y340 w360 h90 ,
-
Gui,2: Add, Text, x26 y350 w330 h20 , The Newest Version of this program is available at:
-
Gui,2: Add, Text, x36 y380 w330 h20 gURL +Border c0000ff Underline, %URL%
-
; Generated using SmartGUI Creator 4.0
-
Gui,2: Show, x431 y292 h455 w399, Update!
-
return
-
-
^+?::
-
Color := MouseGetColor()
-
gosub, SetColors
-
return
-
-
ChooseColor:
-
Color := ChooseColor()
-
gosub, SetColors
-
return
-
-
SetColors:
-
SampInt++
-
StringRight,MouseColor,MouseColor,6
-
-
guicontrol,hide,sampcolor
-
Gui, Add, Progress, x256 y20 w30 h310 vSampColor%SampInt% c%Color%, 100
-
-
guicontrol,,RegHex,%Color%
-
guicontrol,,HTMLHex,#%Color%
-
guicontrol,,Wc3Hex,|cff%Color%
-
return
-
-
GuiClose:
-
Exit:
-
AnimateWindow(hWnd,FADE_DUR,FADE_OUT)
-
ExitApp
-
-
Mini:
-
If mini=1
-
{
-
Gui, +AlwaysOnTop
-
mini=0
-
GuiControl,,MiniText,__
-
WinMove, %title%,, %GUI_START_X%, %GUI_START_Y%
-
Gui, hide
-
AnimateWindow(hWnd,SLIDE_DUR,SLIDE_BOTTOM_TO_TOP)
-
}
-
else
-
{
-
Gui, -AlwaysOnTop
-
mini=1
-
GuiControl,,MiniText,^
-
WinMove, %title%,, %GUI_START_X%, %GUI_MINI_Y%
-
}
-
return
-
-
; ########################
-
; ##### Functions ########
-
; ########################
-
-
;---AnimateWindow---
-
AnimateWindow(hWnd,Duration,Flag) {
-
Return DllCall("AnimateWindow","UInt",hWnd,"Int",Duration,"UInt",Flag)
-
}
-
-
;---MouseGetColor---
-
MouseGetColor() {
-
MouseGetPos,x,y
-
PixelGetColor,c,x,y,RGB
-
return %c%
-
}
-
-
;---ChooseColor---
-
ChooseColor( Color=0x0, hPar=0x0, ccFile="") {
-
Color := SubStr(Color,1,2)="0x" ? Color : "0x" Color ; Check & Prefix Color with "0x"
-
VarSetCapacity(CHOOSECOLOR, 36, 0) , mainPtr := (&CHOOSECOLOR) ; Create Main structure
-
DllCall( "RtlFillMemory", UInt,mainPtr+0, Int,1, UChar,36 ) ; Insert size of the Structure
-
-
hPar := WinExist(ahk_id %hPar%) ; Validate the passed Parent window ID
-
; Break Parent window ID into 4 bytes
-
H1 := hPar>>0 & 255, H2 := hPar>>8 & 255, H3 := hPar>>16 & 255, H4 := hPar>>24 & 255
-
Loop 4 ; Insert Parent window ID to CHOOSECOLOR structure @ Offset 4
-
DllCall( "RtlFillMemory", UInt,mainPtr+3+A_Index, Int,1, UChar,H%A_Index% )
-
-
; Break Color into R,G and B values
-
RGB1 := Color>>16 & 255, RGB2 := Color>>8 & 255, RGB3 := Color>>0 & 255
-
Loop 3 ; Insert R,G and B values to CHOOSECOLOR structure @ Offset 12
-
DllCall( "RtlFillMemory", UInt,mainPtr+11+A_Index, Int,1, UChar,RGB%A_Index% )
-
-
; CustomColors ( CUS1 will be primary array and CUS2 will be a copy to detect any change )
-
VarSetCapacity(CUS1, 64, 0), aPtr := (&CUS1), VarSetCapacity(CUS2, 64, 0)
-
IfEqual,ccFile,, SetEnv,ccFile,%A_WinDir%CUSTOMCOLOR.BIN ; Assign default save filename
-
IfExist,%ccFile%, FileRead,CUS1, *m64 %ccFile% ; Array CUS1 will be overwritten
-
Loop 64 ; Copy data from CUS1 to CUS2
-
oS:=A_Index-1, DllCall( "RtlFillMemory", UInt,&CUS2+oS, Int,1, UChar,*(&CUS1+oS) )
-
A1 := aPtr>>0 & 255, A2 := aPtr>>8 & 255, A3 := aPtr>>16 & 255, A4 := aPtr>>24 & 255
-
Loop 4 ; Insert pointer to Custom colors array to CHOOSECOLOR structure @ Offset 16
-
DllCall( "RtlFillMemory", UInt,mainPtr+15+A_Index, Int,1, UChar,A%A_Index% )
-
-
; Insert Integer 259 @ Offset 21 (259 is CC_RGBINIT + CC_FULLOPEN + CC_ANYCOLOR )
-
DllCall( "RtlFillMemory", UInt,mainPtr+20, Int,1,UChar,3 ) ; CC_RGBINIT=1 + CC_FULLOPEN=2
-
DllCall( "RtlFillMemory", UInt,mainPtr+21, Int,1,UChar,1 ) ; CC_ANYCOLOR=256
-
-
If ! DllCall("comdlg32ChooseColorA", str, CHOOSECOLOR) OR errorLevel ; Call ChooseColor
-
Return -1 ; and return -1 in case of an error or if no color was selected.
-
-
Loop 64 ; Compare data CUS2 and CUS1, if custom color changed, then save array to BIN file
-
If ( *(&CUS1+A_Index-1) != *(&CUS2+A_Index-1) ) { ; Check byte by byte
-
h := DllCall( "_lcreat", Str,ccFile, Int,0 ) ; Overwrite/create file
-
DllCall( "_lwrite", UInt,h, Str,CUS1, Int,64 ) ; write the array,
-
DllCall( "_lclose", UInt,h ) ; close the file,
-
Break ; break the loop.
-
}
-
Hex := "123456789ABCDEF0", RGB := mainPtr+11
-
Loop 3 ; Extract nibbles directly from main structure and convert it into Hex (initd. abv)
-
HexColorCode .= SubStr(Hex, (*++RGB >> 4), 1) . SubStr(Hex, (*RGB & 15), 1)
-
Return HexColorCode ; finally ... phew!
-
}
반응형
'AUTOHOTKEY > 스크립트' 카테고리의 다른 글
AHK Automated Installation (0) | 2007.11.04 |
---|---|
#INCLUDE SQLite.ahk - Functions to access SQLite3 DB's (0) | 2007.11.04 |
이미지파일을 HEX 변환 생성하는 프로그램 (0) | 2007.10.24 |
암호 인코드 디코드 (0) | 2007.10.23 |
숫자에 콤마 찍기 (0) | 2007.10.23 |
Comments