Download: yandex
1. Add a tool with two parameters "%FILE" "%TEMPFILE". If the file is not saved, then "%FILE" will be empty, and "%TEMPFILE" will be used.
2. Make a call to the hotkey on the first source, then make a call on the second source, and eventually the program for comparing the two sources will open.
ini file is created upon first launch.
firstsrc = here the path to the first source is saved
prog = C:\Program Files\WinMerge\WinMergeU.exe - comparison program
arg = "%f1" "%f2" - parameters where %f1 will be replaced with the 1st source, and %f2 with the second one. You can add /e /x
time = 1734071247 - the timestamp for resetting the first source
timediff = 300 - the time interval after which the first source is reset if the comparison is not performed
Code: Select all
;- TOP
; AZJIO 13.12.2024
EnableExplicit
#q$ = Chr(34)
Define UserIntLang
;- Get Language
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Define *Lang
If OpenLibrary(0, "kernel32.dll")
*Lang = GetFunction(0, "GetUserDefaultUILanguage")
If *Lang And CallFunctionFast(*Lang) = 1049 ; ru (embed your language natively)
UserIntLang = 1
EndIf
CloseLibrary(0)
EndIf
CompilerCase #PB_OS_Linux
If ExamineEnvironmentVariables()
While NextEnvironmentVariable()
If Left(EnvironmentVariableName(), 4) = "LANG" And Left(EnvironmentVariableValue(), 2) = "ru" ; (embed your language natively)
; LANG=ru_RU.UTF-8
; LANGUAGE=ru
UserIntLang = 1
Break
EndIf
Wend
EndIf
CompilerEndSelect
;- Language En
Define Dim Lng.s(4)
Lng(0) = "First launch"
Lng(1) = "Check that the comparison program exists:"
Lng(2) = "Comparison program missing:"
Lng(3) = "Parameter error"
Lng(4) = "The program should receive one parameter - the path to the source"
If UserIntLang
Lng(0) = "Певый запуск"
Lng(1) = "Проверте, что программа сравнения существует:"
Lng(2) = "Отсутствует программа сравнения:"
Lng(3) = "Ошибка параметров"
Lng(4) = "Программа должна получить один параметр - путь к исходнику"
EndIf
; Читаем ini-файл, чтобы определить является ли это первый вызов
;- ini
Define time, timediff
Define firstsrc$, prog$, SourceFile$, arg$
Define ini$
ini$ = GetPathPart(ProgramFilename()) + GetFilePart(ProgramFilename(), #PB_FileSystem_NoExtension) + ".ini"
If OpenPreferences(ini$)
; call = ReadPreferenceInteger("call", 0)
firstsrc$ = ReadPreferenceString("firstsrc", "")
prog$ = ReadPreferenceString("prog", "")
arg$ = ReadPreferenceString("arg", #q$ + "%f1" + #q$ + " " + #q$ + "%f2" + #q$)
time = ReadPreferenceInteger("time", 0)
timediff = ReadPreferenceInteger("timediff", 300)
ClosePreferences()
Else
; тут надо создать ini-файл, вместо выхода
If CreatePreferences(ini$)
WritePreferenceString("firstsrc", ProgramParameter())
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
prog$ = "C:\Program Files\WinMerge\WinMergeU.exe"
CompilerElse
prog$ = "meld"
CompilerEndIf
WritePreferenceString("prog", prog$)
WritePreferenceString("arg", #q$ + "%f1" + #q$ + " " + #q$ + "%f2" + #q$)
WritePreferenceInteger("time", Date())
WritePreferenceInteger("timediff", 300)
ClosePreferences()
RunProgram(ini$)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
If FileSize(prog$) < 5
MessageRequester(Lng(0), Lng(1) + #LF$ + #LF$ + prog$)
EndIf
CompilerEndIf
End
EndIf
EndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
If FileSize(prog$) < 5
MessageRequester("", Lng(2) + #LF$ + #LF$ + prog$)
End
EndIf
CompilerEndIf
;- Parameters
; CountParam = CountProgramParameters()
If CountProgramParameters() > 0 And CountProgramParameters() < 3
SourceFile$ = ProgramParameter()
If Not Asc(SourceFile$) And CountProgramParameters() = 2
SourceFile$ = ProgramParameter()
EndIf
If Asc(firstsrc$) And ((Date() - time) < timediff)
If firstsrc$ <> SourceFile$ And FileSize(firstsrc$) > -1 And FileSize(SourceFile$) > -1
arg$ = ReplaceString(arg$, "%f1", firstsrc$)
arg$ = ReplaceString(arg$, "%f2", SourceFile$)
RunProgram(prog$, arg$, "")
; RunProgram(prog$, firstsrc$ + " " + SourceFile$, "")
; Сбрасываем путь
If OpenPreferences(ini$)
WritePreferenceString("firstsrc", "")
ClosePreferences()
End
EndIf
EndIf
Else
If OpenPreferences(ini$)
; Если путь не существует в ini-файле, то это вызов для первого файла. Соответственно сохраняем путь и закрываем.
WritePreferenceString("firstsrc", SourceFile$)
WritePreferenceInteger("time", Date())
ClosePreferences()
End
EndIf
EndIf
Else
MessageRequester(Lng(3), Lng(4))
End
EndIf