;AHK1.1.22.09 Unicode
Result := FileCopyEx(A_SysDir() "\imageres.dll", A_Desktop "\~imageres.dll",, "InfoCopy")
Progress, Off
MsgBox % "Return: " Result "`nErrorLevel: " ErrorLevel
ExitApp
InfoCopy(TotalBytes, BytesWritten, Percent) {
Progress, % Percent, %Percent% `% Completado...`nBytes Totales: %TotalBytes%`nBytes Escritos: %BytesWritten%
if GetKeyState("w") ;stop copying while "w" is pressed
return 3
else {
Sleep 250
return 1
}
Sleep 250
}
FileCopyEx(Filename, Dest := "", OverWrite := false, Func := "", Flags := "") {
SplitPath, Filename, ffn ;, dir, ext, fn, drive
Dest := Dest=""?A_WorkingDir "\" ffn:GetFullPathName(Dest)
if !(OverWrite) && (FileExist(Dest))
return false, ErrorLevel := 2
if !(IsObject(sf:=FileOpen(Filename, "r-wd"))) || !(IsObject(df:=FileOpen(Dest, "w-rwd", sf.Encoding)))
return false, sf.Close(), ErrorLevel := 4
RemainingBytes := Bytes := sf.Length, Count := Floor(Bytes/1000000), df.Length := Count?1000000:Bytes, TotalBytesWritten := 0
Loop, % (Count?Count+1:1) {
if (RemainingBytes>999999) {
VarSetCapacity(Data, 1000000), sf.RawRead(Data, 1000000)
, TotalBytesWritten := TotalBytesWritten+df.RawWrite(Data, 1000000)
} else {
VarSetCapacity(Data, RemainingBytes), sf.RawRead(Data, RemainingBytes)
, TotalBytesWritten := TotalBytesWritten+df.RawWrite(Data, RemainingBytes)
if !(Count) && (IsFunc(Func)) && (%Func%(Bytes, TotalBytesWritten, 100)=0)
return TotalBytesWritten=Bytes, sf.Close(), df.Close(), ErrorLevel := 3
break
} RemainingBytes := RemainingBytes-1000000, VarSetCapacity(Data, 0), df.Length := TotalBytesWritten
if (IsFunc(Func)) {
Percent(10000, TotalBytesWritten / Bytes, Percent)
if ((fReturn:=%Func%(Bytes, TotalBytesWritten, RemainingBytes>999999?Percent:100))=false) {
return false, sf.Close(), df.Close(), ErrorLevel := 3
} else if (fReturn=2) {
Func := ""
} else if (fReturn=3) {
while !(%Func%(Bytes, TotalBytesWritten, RemainingBytes>999999?Percent:100)=1)
Sleep, 1000
}}} sf.Close(), df.Close()
if (Ok:=(TotalBytesWritten=Bytes)) {
if !(Flags[1]) ;CopyAttrib
FileSetAttrib("+" FileGetAttrib(Filename), Dest)
if !(Flags[2]) ;CopyTime
FileSetTime(FileGetTime(Filename, "MCA"), Dest)
} return Ok, ErrorLevel := !Ok
}
FileSetAttrib(Attributes, FilePattern, OperateOnFolders := false, Recurse := false) {
FileSetAttrib, %Attributes%, %FilePattern%, %OperateOnFolders%, %Recurse%
return !ErrorLevel
}
FileGetAttrib(Filename) {
FileGetAttrib, OutputVar, %Filename%
return OutputVar
}
FileGetTime(Filename, WhichTime := "M") {
OutputVar := []
Loop, Parse, % WhichTime
{ FileGetTime, Time, %Filename%, %WhichTime%
if !(Time="")
OutputVar.Push(Time)
} return OutputVar.MaxIndex()=1?OutputVar[1]:OutputVar
}
FileSetTime(Time := "", FilePattern := "", WhichTimeMCA := "M", OperateOnFolders := false, Recurse := false) {
if IsObject(Time)
for k, v in Time
FileSetTime, %v%, %FilePattern%, % k=1?"M":k=2?"C":k=3?"A":k, %OperateOnFolders%, %Recurse%
else Loop, Parse, % WhichTimeMCA
FileSetTime, %Time%, %FilePattern%, %A_LoopField%, %OperateOnFolders%, %Recurse%
return !ErrorLevel
}
Percent(num, Percent, ByRef OutputPercent := "", Places := 2) {
return Float(num-(i:=(num/100)*Percent), "0." Places), OutputPercent := IsByRef(OutputPercent)?Round(i, Places):""
}
Float(num, Type := "0.2") {
return Format("{:" Type (RegExReplace(Type, "[^fegaEGA]")?"":"f") "}", num)
}
GetFullPathName(Filename, ByRef Length := "") {
Size := DllCall("Kernel32.dll\GetFullPathNameW", "Str", Filename, "UInt", 0, "Ptr", 0, "PtrP", 0, "UShort"), VarSetCapacity(OutputVar, Size * 2, 0)
, Length := DllCall("Kernel32.dll\GetFullPathNameW", "Str", Filename, "UInt", Size, "Str", OutputVar, "PtrP", 0, "UShort")
return Length?RTrim(OutputVar, "\"):Filename, ErrorLevel := !Length
}
A_SysDir() {
static SysDir
if !(SysDir)
uSize := DllCall("kernel32.dll\GetSystemDirectoryW", "Ptr", 0, "UInt", 0)
, VarSetCapacity(SysDir, uSize * 2, 0)
, DllCall("kernel32.dll\GetSystemDirectoryW", "Str", SysDir, "UInt", uSize)
return SysDir
}