CheckHash
Posted: Thu Sep 04, 2025 7:54 pm
CheckHash
Download
Screenshot on Linux

ForCheckHash.pb
Download
Screenshot on Linux

Code: Select all
;- TOP
;- @AZJIO v0.2 (05.09.2025)
; план: проверить файлы при запуске утилиты по списку
EnableExplicit
Define UserIntLang, *Lang
If OpenLibrary(0, "kernel32.dll")
*Lang = GetFunction(0, "GetUserDefaultUILanguage")
If *Lang
UserIntLang = CallFunctionFast(*Lang)
EndIf
CloseLibrary(0)
EndIf
#CountStrLang = 21
Global Dim Lng.s(#CountStrLang)
Lng(1) = "About"
Lng(2) = "File 1:"
Lng(3) = "copy hash to clipboard"
Lng(4) = "File 2:"
Lng(5) = "Compare"
Lng(6) = "Compare hash fields"
Lng(7) = "Change hash type"
Lng(8) = "Clear 'File 2' when pasting into 'File 1'"
Lng(9) = "Warning"
Lng(10) = "Drag and drop a single file"
Lng(11) = "Calculate?"
Lng(12) = "The file has been changed and exists, do you want to calculate for it?"
Lng(13) = "Select a file"
Lng(14) = "All"
Lng(15) = "Author"
Lng(16) = "Hash fields must be filled in"
Lng(17) = "Match"
Lng(18) = "Difference"
Lng(19) = "The same file"
Lng(20) = "Match, file size ratio 1=1"
Lng(21) = "Difference, file size ratio"
If UserIntLang = 10149 ; ru
Lng(1) = "О программе"
Lng(2) = "Файл 1:"
Lng(3) = "копировать хеш в буфер обмена"
Lng(4) = "Файл 2:"
Lng(5) = "Сравнить"
Lng(6) = "Сравить поля хешей"
Lng(7) = "Сменить тип хеша"
Lng(8) = "Очищать 'Файл 2' при вставке в 'Файл 1'"
Lng(9) = "Предупреждение"
Lng(10) = "Перетаскивайте одиночный файл"
Lng(11) = "Вычислить?"
Lng(12) = "Файл изменён и существует, хотите вычислить для него?"
Lng(13) = "Выбрать файл"
Lng(14) = "Все"
Lng(15) = "Автор"
Lng(16) = "Поля хешей должны быть заполнены"
Lng(17) = "Совпадение"
Lng(18) = "Отличие"
Lng(19) = "Один и тот же файл"
Lng(20) = "Совпадение, отношение размеров файла 1=1"
Lng(21) = "Отличие, отношение размеров файла"
EndIf
UseMD5Fingerprint()
UseCRC32Fingerprint()
UseSHA1Fingerprint()
UseSHA2Fingerprint()
UseSHA3Fingerprint()
;- # Constants
#Window = 0
#Menu = 0
;- ● Enumeration
; Enumeration
; #Font1
; #FontDef
; EndEnumeration
Enumeration
#mMD5 = 1
#mCRC32
#mSHA1
#mSHA2
#mSHA3
EndEnumeration
Enumeration
#btn
#chk
#txt1
#file_1
#tfilen_1
#openfile_1
#hash_1
#hashbuf_1
#txt2
#file_2
#tfilen_2
#openfile_2
#hash_2
#hashbuf_2
#Sel_Hash
#ClearInp
#Compare_Hash
#CatchDrop1
#About
#StatusBar
EndEnumeration
Structure File
path.s
hash.s
size.q
EndStructure
;- ● Global
Global file1.File
Global file2.File
Global tmp$, HashType, ini$, PathConfig$
Global w, h, gh, gmh, margin, bw, bw1
Global cDefault = 0
Global cRed = $0000EE
Global cGreen = $007700
Global cBlue = $990000
Global Dim aHashType.s(5)
aHashType(1) = "MD5"
aHashType(2) = "CRC32"
aHashType(3) = "SHA1"
aHashType(4) = "SHA2"
aHashType(5) = "SHA3"
;- ● Define
Define hicon1, hicon2
Define style, fsz, cb
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
style = #SS_CENTERIMAGE | #SS_LEFTNOWORDWRAP
CompilerElse
style = 0
CompilerEndIf
;- ● Declare
Declare SetGColor(Color)
Declare CompareFiles()
Declare CompareHash()
Declare SetFile(*file.File, *path, tfilen, file, hash)
XIncludeFile "ForCheckHash.pb"
; LoadFont(#Font1, "", 0, #PB_Font_Bold)
; LoadFont(#FontDef, "", 0)
HashType = #PB_Cipher_MD5
w = 550
h = 208
cb = 0
;- ● ini
PathConfig$ = GetPathPart(ProgramFilename())
If FileSize(PathConfig$ + "CheckHash.ini") = -1
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
PathConfig$ = GetHomeDirectory() + "AppData\Roaming\CheckHash\"
CompilerCase #PB_OS_Linux
PathConfig$ = GetHomeDirectory() + ".config/CheckHash/"
If CreateDirectory(PathConfig$)
; Файл находится в установочном пакете
CopyFile("/usr/share/azjio/CheckHash/CheckHash.ini", PathConfig$ + "CheckHash.ini")
EndIf
; CompilerCase #PB_OS_MacOS
; PathConfig$ = GetHomeDirectory() + "Library/Application Support/CheckHash/"
CompilerEndSelect
EndIf
; Debug PathConfig$
ini$ = PathConfig$ + "CheckHash.ini"
If OpenPreferences(ini$)
w = ReadPreferenceInteger("width", w)
h = ReadPreferenceInteger("height", h)
HashType = ReadPreferenceInteger("HashType", HashType)
Limit(@HashType, 1, 5)
cb = ReadPreferenceInteger("checkbox", cb)
; maxsize = ReadPreferenceInteger("maxsize", maxsize)
cDefault = ColorValidate(ReadPreferenceString("Default", ""), cDefault)
cRed = ColorValidate(ReadPreferenceString("Red", ""), cRed)
cGreen = ColorValidate(ReadPreferenceString("Green", ""), cGreen)
cBlue = ColorValidate(ReadPreferenceString("Blue", ""), cBlue)
ClosePreferences()
EndIf
gh = h / 8
gmh = gh - 2
margin = 10
bw = w - gh - margin * 2
bw1 = gh * 3
Procedure SizeWindowHandler()
Protected w1, h1;, kW.f, kH.f, tmp
w1 = WindowWidth(#Window)
h1 = WindowHeight(#Window)
; kW = w1 / w
; kH = h1 / h
gh = h1 / 8
gmh = gh - 2
margin = 10
bw = w1 - gh - margin * 2
bw1 = gh * 3
; tmp = kW * 24
ResizeGadget(#About, w1 - gh, 0, gmh, gmh)
; tmp = kH * 21
ResizeGadget(#StatusBar, margin, gh * 7, w1 - margin, gmh)
ResizeGadget(#txt1, margin, 0, bw1, gmh)
ResizeGadget(#tfilen_1, margin + bw1, 0, w1 - margin - bw1 - gmh, gmh)
ResizeGadget(#file_1, margin, gh, bw, gmh)
ResizeGadget(#openfile_1, bw + margin, gh, gmh, gmh)
ResizeGadget(#hash_1, margin, gh * 2, bw, gmh)
ResizeGadget(#hashbuf_1, bw + margin, gh * 2, gmh, gmh)
ResizeGadget(#txt2, margin, gh * 3, bw1, gmh)
ResizeGadget(#tfilen_2, margin + bw1, gh * 3, w1 - margin - bw1 - gmh, gmh)
ResizeGadget(#file_2, margin, gh * 4, bw, gmh)
ResizeGadget(#openfile_2, bw + margin, gh * 4, gmh, gmh)
ResizeGadget(#hash_2, margin, gh * 5, bw, gmh)
ResizeGadget(#hashbuf_2, bw + margin, gh * 5, gmh, gmh)
ResizeGadget(#Compare_Hash, margin, gh * 6, bw1 + margin * 3, gmh)
ResizeGadget(#Sel_Hash, margin * 4 + bw1 , gh * 6, bw1 + margin, gmh)
ResizeGadget(#ClearInp, margin * 6 + bw1 * 2, gh * 6, w1 - margin * 7 - bw1 * 2, gmh)
; ResizeGadget()
EndProcedure
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
; https://www.purebasic.fr/english/viewtopic.php?p=531374#p531374
ImportC ""
gtk_window_set_icon(a.l,b.l)
EndImport
UseGIFImageDecoder()
;- DataSection
DataSection
IconTitle:
IncludeBinary "images" + #PS$ + "icon.gif"
folder:
IncludeBinary "images" + #PS$ + "folder.gif"
copy:
IncludeBinary "images" + #PS$ + "copy.gif"
EndDataSection
CatchImage(0, ?IconTitle)
CatchImage(1, ?copy)
CatchImage(2, ?folder)
CompilerEndIf
;-┌──GUI──┐
If OpenWindow(#Window, 0, 0, w, h, "CheckHash",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
gtk_window_set_icon_(WindowID(#Window), ImageID(0)) ; назначаем иконку в заголовке
CompilerEndIf
WindowBounds(#Window , 500 , 208 , #PB_Ignore , #PB_Ignore)
ButtonGadget(#About, w - gh, 0, gmh, gmh, "@")
GadgetToolTip(#About, Lng(1))
; TextGadget(#StatusBar, margin, h - gmh, w - margin, gmh, "Строка состояния")
TextGadget(#StatusBar, margin, gh * 7, w - margin, gmh, "AZJIO 2025", style)
; TextGadget(#CatchDrop1, 0, 30, w, 70, "")
; DisableGadget(#CatchDrop1, 1)
;- ├ Файл группа 1
TextGadget(#txt1, margin, 0, bw1, gmh, Lng(2), style)
TextGadget(#tfilen_1, margin + bw1, 0, w - margin - bw1 - gmh, gmh, "", style)
SetGadgetColor(#tfilen_1, #PB_Gadget_FrontColor, cBlue)
; SetGadgetFont(#tfilen_1, FontID(#Font1))
StringGadget(#file_1, margin, gh, bw, gmh, "")
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
ExtractIconEx_("Shell32.dll", 3, 0, @hicon1, 1)
ButtonImageGadget(#openfile_1, bw + margin, gh, gmh, gmh, hicon1)
CompilerElse
ButtonImageGadget(#openfile_1, bw + margin, gh, gmh, gmh, ImageID(2))
CompilerEndIf
StringGadget(#hash_1, margin, gh * 2, bw, gmh, "")
; SetGadgetFont(#tfilen_1, FontID(#Font1))
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
ExtractIconEx_("Shell32.dll", 54, 0, @hicon2, 1)
ButtonImageGadget(#hashbuf_1, bw + margin, gh * 2, gmh, gmh, hicon2)
CompilerElse
ButtonImageGadget(#hashbuf_1, bw + margin, gh * 2, gmh, gmh, ImageID(1))
CompilerEndIf
GadgetToolTip(#hashbuf_1, Lng(3))
;- ├ Файл группа 2
TextGadget(#txt2, margin, gh * 3, bw1, gmh, Lng(4), style)
TextGadget(#tfilen_2, margin + bw1, gh * 3, w - margin - bw1 - gmh, gmh, "", style)
SetGadgetColor(#tfilen_2, #PB_Gadget_FrontColor, cBlue)
; SetGadgetFont(#tfilen_2, FontID(#Font1))
StringGadget(#file_2, margin, gh * 4, bw, gmh, "")
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
ExtractIconEx_("Shell32.dll", 3, 0, @hicon1, 1)
ButtonImageGadget(#openfile_2, bw + margin, gh * 4, gmh, gmh, hicon1)
CompilerElse
ButtonImageGadget(#openfile_2, bw + margin, gh * 4, gmh, gmh, ImageID(2))
CompilerEndIf
StringGadget(#hash_2, margin, gh * 5, bw, gmh, "")
; SetGadgetFont(#tfilen_2, FontID(#Font1))
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
ExtractIconEx_("Shell32.dll", 54, 0, @hicon2, 1)
ButtonImageGadget(#hashbuf_2, bw + margin, gh * 5, gmh, gmh, hicon2)
CompilerElse
ButtonImageGadget(#hashbuf_2, bw + margin, gh * 5, gmh, gmh, ImageID(1))
CompilerEndIf
GadgetToolTip(#hashbuf_2, Lng(3))
ButtonGadget(#Compare_Hash, margin, gh * 6, bw1 + margin * 3, gmh, Lng(5))
GadgetToolTip(#Compare_Hash, Lng(6))
ButtonGadget(#Sel_Hash, margin * 4 + bw1 , gh * 6, bw1 + margin, gmh, "")
SetGadgetText(#Sel_Hash , aHashType(HashType))
; Select HashType
; Case 1
; SetGadgetText(#Sel_Hash , "MD5")
; Case 2
; SetGadgetText(#Sel_Hash , "CRC32")
; Case 3
; SetGadgetText(#Sel_Hash , "SHA1")
; Case 4
; SetGadgetText(#Sel_Hash , "SHA2")
; Case 5
; SetGadgetText(#Sel_Hash , "SHA3")
; EndSelect
GadgetToolTip(#Sel_Hash, Lng(7))
CheckBoxGadget(#ClearInp, margin * 6 + bw1 * 2, gh * 6, w - margin * 7 - bw1 * 2, gmh, Lng(8))
If cb
SetGadgetState(#ClearInp, #PB_Checkbox_Checked)
EndIf
EnableGadgetDrop(#file_1, #PB_Drop_Files, #PB_Drag_Copy)
EnableGadgetDrop(#file_2, #PB_Drop_Files, #PB_Drag_Copy)
EnableGadgetDrop(#hash_1, #PB_Drop_Files, #PB_Drag_Copy)
EnableGadgetDrop(#hash_2, #PB_Drop_Files, #PB_Drag_Copy)
BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler())
;- ├ Menu
If CreatePopupMenu(#Menu)
MenuItem(#mMD5, "MD5")
MenuItem(#mCRC32, "CRC32")
MenuItem(#mSHA1, "SHA1")
MenuItem(#mSHA2, "SHA2")
MenuItem(#mSHA3, "SHA3")
CloseSubMenu()
EndIf
; Здесь параметры командной строки.
; Передаются 1 или 2 параметра, каждый из которых абсолютный путь или хеш из 16-ричных символов.
If CountProgramParameters()
tmp$ = ProgramParameter(0)
fsz = FileSize(tmp$)
If fsz > - 1
file1\size = fsz
SetFile(@file1, @tmp$, #tfilen_1, #file_1, #hash_1)
ElseIf IsHex(@tmp$)
SetGadgetText(#hash_2, tmp$)
EndIf
If CountProgramParameters() > 1
tmp$ = ProgramParameter(1)
fsz = FileSize(tmp$)
If fsz > - 1
file2\size = fsz
SetFile(@file2, @tmp$, #tfilen_2, #file_2, #hash_2)
ElseIf IsHex(@tmp$)
SetGadgetText(#hash_2, tmp$)
CompareHash()
EndIf
EndIf
EndIf
;-┌──Loop──┐
Repeat
Select WaitWindowEvent()
;- ├ Drop
Case #PB_Event_GadgetDrop
fsz = FileSize(EventDropFiles())
If fsz < 0 Or FindString(EventDropFiles(), Chr(10))
MessageRequester(Lng(9), Lng(10))
Continue
EndIf
tmp$ = EventDropFiles()
; IsFolder = FileSize(EventDropFiles())
Select EventGadget()
Case #file_1, #hash_1 ; гаджеты, получившие событие перетаскивания файла/папки
file1\size = fsz
If GetGadgetState(#ClearInp) & #PB_Checkbox_Checked
SetGadgetText(#tfilen_2, "")
SetGadgetText(#file_2, "")
SetGadgetText(#hash_2, "")
SetGadgetText(#StatusBar, "")
file2\hash = ""
file2\path = ""
file2\size = 0
EndIf
SetFile(@file1, @tmp$, #tfilen_1, #file_1, #hash_1)
Case #file_2, #hash_2
file2\size = fsz
SetFile(@file2, @tmp$, #tfilen_2, #file_2, #hash_2)
EndSelect
;- ├ Gadget
Case #PB_Event_Gadget
Select EventGadget()
Case #file_1
If EventType() = #PB_EventType_Change
tmp$ = GetGadgetText(#file_1)
If file1\path <> tmp$
fsz = FileSize(tmp$)
If fsz > - 1
If MessageRequester(Lng(11), Lng(12),
#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
file1\size = fsz
SetFile(@file1, @tmp$, #tfilen_1, #file_1, #hash_1)
EndIf
EndIf
EndIf
EndIf
Case #file_2
If EventType() = #PB_EventType_Change
tmp$ = GetGadgetText(#file_2)
If file2\path <> tmp$
fsz = FileSize(tmp$)
If fsz > - 1
If MessageRequester(Lng(11), Lng(12),
#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
file2\size = fsz
SetFile(@file2, @tmp$, #tfilen_2, #file_2, #hash_2)
EndIf
EndIf
EndIf
EndIf
Case #openfile_1
tmp$ = OpenFileRequester(Lng(13), GetCurrentDirectory(), Lng(14) + " (*.*)|*.*|exe|*.exe", 0)
If Asc(tmp$)
file1\size = FileSize(tmp$)
If GetGadgetState(#ClearInp) & #PB_Checkbox_Checked
SetGadgetText(#tfilen_2, "")
SetGadgetText(#file_2, "")
SetGadgetText(#hash_2, "")
SetGadgetText(#StatusBar, "")
file2\hash = ""
file2\path = ""
file2\size = 0
EndIf
SetFile(@file1, @tmp$, #tfilen_1, #file_1, #hash_1)
EndIf
Case #openfile_2
tmp$ = OpenFileRequester(Lng(13), GetCurrentDirectory(), Lng(14) + " (*.*)|*.*|exe|*.exe", 0)
If Asc(tmp$)
file2\size = FileSize(tmp$)
SetFile(@file2, @tmp$, #tfilen_2, #file_2, #hash_2)
EndIf
Case #hashbuf_1
SetClipboardText(GetGadgetText(#hash_1))
Case #hashbuf_2
SetClipboardText(GetGadgetText(#hash_2))
Case #Sel_Hash
DisplayPopupMenu(#Menu, WindowID(#Window))
Case #Compare_Hash
CompareHash()
Case #About
MessageRequester(Lng(1), Lng(15) + " AZJIO" + #LF$ + "v0.2 05.09.2025")
EndSelect
;- ├ Menu
Case #PB_Event_Menu
tmp$ = GetGadgetText(#Sel_Hash)
; Не очень правильно, так номер события используется как константа хеша, далее Select это правильный метод, заложили проблему
HashType = EventMenu()
SetGadgetText(#Sel_Hash, aHashType(HashType))
; Select EventMenu()
; ; Case #mCRC32 To #mSHA3
; ; ChangingHashType(em)
; Case #mCRC32
; HashType = #PB_Cipher_CRC32
; SetGadgetText(#Sel_Hash, "CRC32")
; Case #mMD5
; HashType = #PB_Cipher_MD5
; SetGadgetText(#Sel_Hash, "MD5")
; Case #mSHA1
; HashType = #PB_Cipher_SHA1
; SetGadgetText(#Sel_Hash, "SHA1")
; Case #mSHA2
; HashType = #PB_Cipher_SHA2
; SetGadgetText(#Sel_Hash, "SHA2")
; Case #mSHA3
; HashType = #PB_Cipher_SHA3
; SetGadgetText(#Sel_Hash, "SHA3")
; EndSelect
If tmp$ <> GetGadgetText(#Sel_Hash)
tmp$ = GetGadgetText(#file_1)
If Asc(tmp$)
fsz = FileSize(tmp$)
If fsz > - 1
file1\size = fsz
SetFile(@file1, @tmp$, #tfilen_1, #file_1, #hash_1)
EndIf
EndIf
tmp$ = GetGadgetText(#file_2)
If Asc(tmp$)
fsz = FileSize(tmp$)
If fsz > - 1
file2\size = fsz
SetFile(@file2, @tmp$, #tfilen_2, #file_2, #hash_2)
EndIf
EndIf
EndIf
Case #PB_Event_CloseWindow
CloseWindow(#Window)
End
EndSelect
ForEver
EndIf
;-└──Loop──┘
; Procedure ChangingHashType(event)
; Protected
; Select event
; Case #mCRC32
; HashType = #PB_Cipher_CRC32
; SetGadgetText(#Sel_Hash, "CRC32")
; Case #mMD5
; HashType = #PB_Cipher_MD5
; SetGadgetText(#Sel_Hash, "MD5")
; Case #mSHA1
; HashType = #PB_Cipher_SHA1
; SetGadgetText(#Sel_Hash, "SHA1")
; Case #mSHA2
; HashType = #PB_Cipher_SHA2
; SetGadgetText(#Sel_Hash, "SHA2")
; Case #mSHA3
; HashType = #PB_Cipher_SHA3
; SetGadgetText(#Sel_Hash, "SHA3")
; EndSelect
; EndProcedure
Procedure SetFile(*file.File, *path, tfilen, file, hash)
Protected *p.string = @*path
*file\path = *p\s
SetGadgetColor(#hash_1, #PB_Gadget_FrontColor, cDefault)
SetGadgetColor(#hash_2, #PB_Gadget_FrontColor, cDefault)
SetGadgetColor(#StatusBar, #PB_Gadget_FrontColor, cDefault)
SetGadgetText(tfilen, GetFilePart(*file\path))
SetGadgetText(file, *file\path)
*file\hash = FileFingerprint(*file\path, HashType)
SetGadgetText(hash, *file\hash)
CompareFiles()
EndProcedure
Procedure CompareHash()
Protected hash1$, hash2$
hash1$ = GetGadgetText(#hash_1)
hash2$ = GetGadgetText(#hash_2)
If Not (Asc(hash1$) And Asc(hash2$))
MessageRequester(Lng(9), Lng(16))
ProcedureReturn
EndIf
; Используем CompareMemoryString(), чтобы сравнивать без учёта регистра,
; то есть если скопировано из другой программы с другим регистром, то это не проблема
If CompareMemoryString(@hash1$ , @hash2$, #PB_String_NoCase) = #PB_String_Equal
SetGColor(cGreen)
SetGadgetText(#StatusBar, Lng(17))
Else
SetGColor(cRed)
SetGadgetText(#StatusBar, Lng(18))
EndIf
EndProcedure
Procedure CompareFiles()
Protected hash1$, hash2$, tmp$, k.d
hash1$ = GetGadgetText(#hash_1)
hash2$ = GetGadgetText(#hash_2)
If Asc(hash2$) = 0 Or Asc(hash1$) = 0
ProcedureReturn
EndIf
If Asc(file1\path) And file1\path = file2\path
SetGadgetText(#StatusBar, Lng(19))
MessageRequester(Lng(9), Lng(19))
ProcedureReturn
EndIf
; Используем CompareMemoryString(), чтобы сравнивать без учёта регистра,
; то есть если скопировано из другой программы с другим регистром, то это не проблема
If CompareMemoryString(@hash1$ , @hash2$, #PB_String_NoCase) = #PB_String_Equal
SetGColor(cGreen)
SetGadgetText(#StatusBar, Lng(20))
Else
SetGColor(cRed)
If file1\size > file2\size
k = file1\size / file2\size
; Debug file1\size
; Debug file2\size
; Debug k
tmp$ = FormatNumber(k, 1, ".", "")
If tmp$ = "1.0"
tmp$ = "1"
EndIf
tmp$ + " > 1"
ElseIf file1\size < file2\size
k = file2\size / file1\size
; Debug file1\size
; Debug file2\size
; Debug k
tmp$ = FormatNumber(k, 1, ".", "")
If tmp$ = "1.0"
tmp$ = "1"
EndIf
tmp$ = "1 < " + tmp$
ElseIf file1\size = file2\size
tmp$ = "1=1"
EndIf
SetGadgetText(#StatusBar, Lng(21) + " " + tmp$)
EndIf
EndProcedure
Procedure SetGColor(Color)
SetGadgetColor(#hash_1, #PB_Gadget_FrontColor, Color)
SetGadgetColor(#hash_2, #PB_Gadget_FrontColor, Color)
SetGadgetColor(#StatusBar, #PB_Gadget_FrontColor, Color)
EndProcedure
Code: Select all
Procedure IsHex(*c.Character)
Protected flag = #True
If *c = 0 Or *c\c = 0
ProcedureReturn 0
EndIf
Repeat
If Not ((*c\c >= '0' And *c\c <= '9') Or (*c\c >= 'a' And *c\c <= 'f') Or (*c\c >= 'A' And *c\c <= 'F'))
flag = #False
Break
EndIf
*c + SizeOf(Character)
Until Not *c\c
ProcedureReturn flag
EndProcedure
Procedure Limit(*Value.integer, Min, Max)
If *Value\i < Min
*Value\i = Min
ElseIf *Value\i > Max
*Value\i = Max
EndIf
EndProcedure
Procedure RGBtoBGR(c)
; ProcedureReturn RGB(Blue(c), Green(c), Red(c))
ProcedureReturn ((c & $00FF00) | ((c & $0000FF) << 16) | ((c & $FF0000) >> 16))
EndProcedure
; def если пустая строка или больше 6 или 5 или 4
; def в BGR, не RGB, то есть готовое для применения
; Color$ это RGB прочитанный из ini с последующим преобразованием в BGR
Procedure ColorValidate(Color$, def = 0)
Protected tmp$, tmp2$, i
; Debug Color$
i = Len(Color$)
If i <= 6 And IsHex(@Color$)
Select i
Case 6
; def = Val("$" + Color$)
; RGBtoBGR2(@def)
def = RGBtoBGR(Val("$" + Color$))
Case 1
def = Val("$" + LSet(Color$, 6, Color$))
Case 2
def = Val("$" + Color$ + Color$ + Color$)
Case 3
; сразу переворачиваем в BGR
For i = 3 To 1 Step -1
tmp$ = Mid(Color$, i, 1)
tmp2$ + tmp$ + tmp$
Next
def = Val("$" + tmp2$)
EndSelect
EndIf
; Debug Hex(def)
ProcedureReturn def
EndProcedure