【HSP3】MPEG2RepairProxy(仮Ver0.02)

MPEG2Repair.exeをバッジ処理するためのプロキシソフト まあまあマシになったver(途中で止まらなくなった)

MPEG2Repair.exeをバッジ処理するためのプロキシソフト まあまあマシになったver(途中で止まらなくなった)

#include "kernel32.as"
#include "user32.as"
#uselib "shlwapi"
#cfunc global PathFileExists "PathFileExistsA" str
#packopt name "MPEG2RepairProxy"
// CONSOLEMODE
#define CONSOLEMODE
#ifdef CONSOLEMODE
#runtime "hsp3cl"
#define ERRORMSG mes
#define LOGMSG mes
#else
#packopt hide 1
#define ERRORMSG dialog
#define LOGMSG logmes
#endif
#module
#deffunc GetWindowList var list, int _max
if _max == 0 : max = 4096 : else : max = _max
VirtualAlloc 0, 12*4, 0x2000/*MEM_RESERVE*/, 0x40/*PAGE_EXECUTE_READWRITE*/
VirtualAlloc stat, 12*4, 0x1000/*MEM_COMMIT*/, 0x40/*PAGE_EXECUTE_READWRITE*/
pbm = stat
dupptr bm, pbm, 12*4, 4
bm.0 = $0824448b, $8b08488b, $ca3b0450, $c033057c, $8b0008c2, $748b5610
bm.6 = $34890824, $08488b8a, $48895e41, $0001b808, $08c20000, $00000000
dim list, max
ENUMWND_DATA = varptr(list), max, 0
EnumWindows pbm, varptr(ENUMWND_DATA)
dim bm
VirtualFree pbm, 12*4, 0x4000 /*MEM_DECOMMIT*/
VirtualFree pbm, 0, 0x8000 /*MEM_RELEASE*/
return
#global
#module
#defcfunc exec2 str _cmd, var pid, int showmode
pid = -1
cmd = _cmd
; STARTUPINFO
dim stinfo, 17
stinfo.0 = 68 ; (cb)
stinfo.11 = 1//STARTF_USESHOWWINDOW
stinfo.12 = showmode & 0xFFFF
; PROCESS_INFOMATION
dim prinfo, 4
;
CreateProcess 0,varptr(cmd),0,0,0,0,0,0,varptr(stinfo),varptr(prinfo)
if (stat == 0) : return 0
hProcess = prinfo.0 ;
hThread = prinfo.1 ;
pid = prinfo.2
;
CloseHandle hThread
hThread = 0
return hProcess
#global
*main
//
cl = dir_cmdline + " "
// test
;cl = "-input \"D:\\DummyTs\\ -output -hide -errorlog ☆ Duumy01.ts\" -output -errorlog -hide -minimize -nooverwrite"
;cl = "-input \"D:\\DummyTs\\Duumy01.ts\" -output"
m_hide = 0
m_minimize = 0
m_overwrite = 1
m_seqnum = 0
sdim m_input : m_input_f = 0
sdim m_output : m_output_f = 0
sdim m_errorlog : m_errorlog_f = 0
mode = 0
p = 0
repeat strlen(cl)
sdim m
//
tmp = strmid(cl, p, 1)
if tmp == "-"{
mode = 1
}else : if tmp == "\""{
mode = 2
}else{
mode = 0
}
if mode == 0{
}
if mode == 1{
i = p
repeat strlen(cl)-p
tmp2 = strmid(cl, i, 1)
//
if tmp2 == " " | tmp2 == "\"" : m = strmid(cl, p, i-p) : p = i : break
//
if cnt == (strlen(cl) - p) - 1 : m = strmid(cl, p, i-p+1) : p = i : break
i++
loop
// -input,-output,-errorlog(input)
if m == "-input"{
m_input_f = 1
mode = 2
}else : if m == "-output"{
m_output_f = 1
mode = 2
}else : if m == "-errorlog"{
m_errorlog_f = 1
mode = 2
}else : if m == ""{
//
}else : if m == "-hide"{
m_hide = 1
}else : if m == "-minimize"{
m_minimize = 1
}else : if m == "-nooverwrite"{
m_overwrite = 0
}else : if m == "-seqnum"{
m_seqnum = 1
}
}
if mode == 2{
i = p
sp = -1 : ep = -1
repeat strlen(cl)-p
tmp2 = strmid(cl, i, 1)
//
if tmp2 == "\"" {
mode_dq = 1
if sp == -1 : sp = i : i++ : continue
if ep == -1 : ep = i : i++ : break
}
i++
loop
//
if sp != -1 && ep != -1 {
p = i //
tmp2 = strmid(cl, sp + 1, ep - sp - 1)
if m == "-input"{
m_input = tmp2
}else : if m == "-output"{
m_output = tmp2
}else : if m == "-errorlog"{
m_errorlog = tmp2
}
}
}
p++
loop
//
if m_input == "" {
ERRORMSG "ERROR:-input " : end
}
if m_output_f == 0{
ERRORMSG "ERROR:-output " : end
}
// 2GBexist使
if PathFileExists(m_input) == 0{
ERRORMSG "ERROR:\n"+m_input : end
}
// MPEG2Repair.exe
if PathFileExists("./MPEG2Repair/MPEG2Repair.exe") == 0{
ERRORMSG "ERROR:MPEG2Repair.exe ./MPEG2Repair/MPEG2Repair.exe" : end
}
//
hProcess = exec2("./MPEG2Repair/MPEG2Repair.exe", pID, 0)
if hProcess == 0{
ERRORMSG "ERROR:MPEG2Repair.exe " : end
}
//
WaitForInputIdle hProcess, 0xFFFFFFFF/*INFINITE*/
// 60(1)
repeat 60
wait 100
//
GetWindowList list, 4096 : hMain = 0 : c_pID = 0
repeat length(list)
sdim name, 256 : sdim class, 256
GetClassNameA list(cnt), varptr(class), 256
GetWindowTextA list(cnt), varptr(name), 256
GetWindowThreadProcessId list(cnt), varptr(c_pID)
if c_pID == pID && class == "#32770" && name == "MPEG2Repair"{
hMain = list(cnt)
break
}
loop
if hMain != 0 : break
LOGMSG "WAIT:... ("+(cnt+1)+"/60)"
loop
if hMain == 0 {
ERRORMSG "ERROR:"
TerminateProcess hProcess, 0
end
}
//
if m_minimize == 1{
ShowWindow hMain, 6
}else : if m_hide == 1{
//
}else{
//
ShowWindow hMain, 4
}
sleep 500
// 1
FindWindowEx hMain, 0, "Edit", 0
hEdit = stat
hStatic = stat
if hEdit == 0 {
ERRORMSG "ERROR:MPEG2Repair(Edit)"
TerminateProcess hProcess, 0
end
}
//
;SetWindowTextA hEdit, varptr(m_input) // 使
SendMessageA hEdit, 0x000C, 0, varptr(m_input)
//
FindWindowEx hMain, 0, "Static", "0 % Complete"
hStatic = stat
if hStatic == 0 {
ERRORMSG "ERROR:MPEG2Repair(Static)"
TerminateProcess hProcess, 0
end
}
// Find PID's
hButton = 0
repeat 60
wait 100
FindWindowEx hMain, 0, "Button", "Find PID's"
hButton = stat
if hButton != 0 : break
LOGMSG "WAIT:... ("+(cnt+1)+"/60)"
loop
if hButton == 0 {
ERRORMSG "ERROR:MPEG2Repair(Button)"
TerminateProcess hProcess, 0
end
}
//
SendMessageA hButton, 0x00F5, 0, 0
// 調
repeat 60
wait 100
sdim string, 256
GetWindowTextA hStatic, varptr(string), 256
if instr(string, 0, "100 % Completed.") != -1 : break
LOGMSG "WAIT:PID... ("+(cnt+1)+"/60)"
loop
if instr(string, 0, "100 % Completed.") == -1 {
ERRORMSG "ERROR:MPEG2RepairPID"
TerminateProcess hProcess, 0
end
}
// Repair Erros
FindWindowEx hMain, 0, "Button", "Repair Errors"
hButton2 = stat
if hButton2 == 0 {
ERRORMSG "ERROR:MPEG2Repair(Button)"
TerminateProcess hProcess, 0
end
}
//
SendMessageA hButton2, 0x00F5, 0, 0
sleep 500
if m_output != ""{
//2
FindWindowEx hMain, hEdit, "Edit", 0
hEdit2 = stat
if hEdit2 == 0 {
ERRORMSG "ERROR:MPEG2Repair(Edit)"
TerminateProcess hProcess, 0
end
}
//
SendMessageA hEdit2, 0x000C, 0, varptr(m_output)
}
//
if m_errorlog_f == 1{
// Log Erros
FindWindowEx hMain, 0, "Button", "Log Errors"
hButton3 = stat
if hButton3 == 0 {
ERRORMSG "ERROR:MPEG2Repair(Button)"
TerminateProcess hProcess, 0
end
}
//
SendMessageA hButton3, 0x00F5, 0, 0
sleep 500
//3
FindWindowEx hMain, hEdit2, "Edit", 0
hEdit3 = stat
if hEdit3 == 0 {
ERRORMSG "ERROR:MPEG2Repair(Edit)"
TerminateProcess hProcess, 0
end
}
//
SendMessageA hEdit3, 0x000C, 0, varptr(m_errorlog)
}
// (SendMessage)
PostMessageA hButton, 0x00F5, 0, 0
wait 50
f = 0
repeat
//
sdim string, 256
GetWindowTextA hStatic, varptr(string), 256
LOGMSG string
gosub *WindowCheck
if f == 1 : break
//
wait 100
loop
TerminateProcess hProcess, 0
LOGMSG "SUCCEED:"
end
*WindowCheck
//
GetWindowList list, 4096
repeat length(list)
sdim class, 256 : sdim name, 256 : c_pid = 0
GetClassNameA list.cnt, varptr(class), 256
GetWindowTextA list.cnt, varptr(name), 256
GetWindowThreadProcessId list.cnt, varptr(c_pid)
//
if class == "#32770" && name == "Warning:" && c_pid == pID{
// OverWrite
hDialog = 0
hDialog2 = list.cnt
repeat
FindWindowEx hDialog2, hDialog, "Static", 0
hDialog = stat
if hDialog == 0 : break
sdim static_string, 1024
GetWindowTextA hDialog, varptr(static_string), 1024
//
if instr(static_string, 0, "Overwrite it?") != -1 {
if m_overwrite == 1{
FindWindowEx hDialog2, 0, "Button", 0
SendMessageA stat, 0x00F5, 0, 0
}else{
FindWindowEx hDialog2, 0, "Button", 0
FindWindowEx hDialog2, stat, "Button", 0
SendMessageA stat, 0x00F5, 0, 0
}
break
}
loop
}
//
if class == "#32770" && name == "Question:" && c_pid == pID{
// OverWrite
hDialog = 0
hDialog2 = list.cnt
repeat
FindWindowEx hDialog2, hDialog, "Static", 0
hDialog = stat
if hDialog == 0 : break
sdim static_string, 1024
GetWindowTextA hDialog, varptr(static_string), 1024
//
if instr(static_string, 0, "numbered sequence") != -1 {
if m_seqnum == 1{
FindWindowEx hDialog2, 0, "Button", 0
SendMessageA stat, 0x00F5, 0, 0
}else{
FindWindowEx hDialog2, 0, "Button", 0
FindWindowEx hDialog2, stat, "Button", 0
SendMessageA stat, 0x00F5, 0, 0
}
break
}
loop
}
//
if class == "#32770" && name == "Status:" && c_pid == pID{
//
FindWindowEx list.cnt, 0, "Button", 0
SendMessageA stat, 0x00F5, 0, 0
f = 1
break
}
loop
return
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX