pintas Posted March 21, 2019 Share Posted March 21, 2019 (edited) Hi! I made a script that reads an ini file and updates the controls background color according to the ini key value. There's another script that needs to write to that ini file, but the file is locked by this main script. The loop keeps updating the window according to the ini contents, and that generates the flickering (and stalls the gui) but it also locks the ini file for writing. I can't think of a logic that could solve my problem. I'm sorry for the big script, the UI is still a bit messed up. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\telmo.baia\desktop\pinshell update utility.kxf $Form1_1 = GUICreate("PinShell Update Utility", 618, 357) $MenuItem1 = GUICtrlCreateMenu("&Arquivo") $MenuItem3 = GUICtrlCreateMenuItem("Abrir arquivo de atualização", $MenuItem1) $MenuItem4 = GUICtrlCreateMenuItem("Sair", $MenuItem1) $RadioUpdAll = GUICtrlCreateRadio("Atualizar todos os micros", 16, 8, 153, 17) $RadioUpdSel = GUICtrlCreateRadio("Selecionar micros a atualizar", 16, 32, 153, 17) $iStart = GUICtrlCreateDummy() $Group1 = GUICtrlCreateGroup("OFFSET", 8, 64, 145, 265) $Check0 = GUICtrlCreateCheckbox("730", 24, 80, 39, 17) $Check1 = GUICtrlCreateCheckbox("419", 24, 96, 39, 17) $Check2 = GUICtrlCreateCheckbox("208", 24, 112, 39, 17) $Check3 = GUICtrlCreateCheckbox("702", 24, 128, 39, 17) $Check4 = GUICtrlCreateCheckbox("418", 24, 144, 39, 17) $Check5 = GUICtrlCreateCheckbox("209", 24, 160, 39, 17) $Check6 = GUICtrlCreateCheckbox("422", 24, 176, 39, 17) $Check7 = GUICtrlCreateCheckbox("218", 24, 192, 39, 17) $Check8 = GUICtrlCreateCheckbox("417", 24, 208, 39, 17) $Check9 = GUICtrlCreateCheckbox("415", 24, 224, 39, 17) $Check10 = GUICtrlCreateCheckbox("205", 24, 240, 39, 17) $Check44 = GUICtrlCreateCheckbox("999", 24, 280, 39, 17) $Label1 = GUICtrlCreateLabel("- 3R707RV-2", 64, 82, 69, 17) $Label2 = GUICtrlCreateLabel("- 4R707RV-1", 64, 98, 69, 17) $Label3 = GUICtrlCreateLabel("- 5R707", 64, 114, 45, 17) $Label4 = GUICtrlCreateLabel("- 7R707RVUV-1", 64, 130, 84, 17) $Label5 = GUICtrlCreateLabel("- 8R706UV", 64, 146, 60, 17) $Label6 = GUICtrlCreateLabel("- 9CD6UV-1", 64, 162, 64, 17) $Label7 = GUICtrlCreateLabel("- 10R701UV-1", 64, 178, 75, 17) $Label8 = GUICtrlCreateLabel("- 13CD74-6RV-1", 64, 194, 85, 17) $Label9 = GUICtrlCreateLabel("- 14R507RV-1", 64, 210, 75, 17) $Label10 = GUICtrlCreateLabel("- 15R506", 64, 226, 51, 17) $Label11 = GUICtrlCreateLabel("- 17CD102-4", 64, 242, 67, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("CORTE E VINCO", 160, 64, 145, 265) $Check11 = GUICtrlCreateCheckbox("522", 176, 80, 39, 17) $Check12 = GUICtrlCreateCheckbox("521", 176, 96, 39, 17) $Check13 = GUICtrlCreateCheckbox("352", 176, 112, 39, 17) $Check14 = GUICtrlCreateCheckbox("351", 176, 128, 39, 17) $Check15 = GUICtrlCreateCheckbox("350", 176, 144, 39, 17) $Check16 = GUICtrlCreateCheckbox("220", 176, 160, 39, 17) $Check17 = GUICtrlCreateCheckbox("416", 176, 176, 39, 17) $Check18 = GUICtrlCreateCheckbox("703", 176, 192, 39, 17) $Check19 = GUICtrlCreateCheckbox("214", 176, 208, 39, 17) $Check20 = GUICtrlCreateCheckbox("212", 176, 224, 39, 17) $Check21 = GUICtrlCreateCheckbox("213", 176, 240, 39, 17) $Check22 = GUICtrlCreateCheckbox("219", 176, 256, 39, 17) $Check23 = GUICtrlCreateCheckbox("731", 176, 272, 39, 17) $Check24 = GUICtrlCreateCheckbox("295", 176, 288, 39, 17) $Label16 = GUICtrlCreateLabel("- VISIO-2", 216, 82, 50, 17) $Label17 = GUICtrlCreateLabel("- VISIO-1", 216, 98, 50, 17) $Label18 = GUICtrlCreateLabel("- NOVAC-3", 216, 114, 59, 17) $Label19 = GUICtrlCreateLabel("- NOVAC-1", 216, 130, 59, 17) $Label20 = GUICtrlCreateLabel("- NOVAC-2", 216, 146, 59, 17) $Label21 = GUICtrlCreateLabel("- SPERIA-1", 216, 162, 61, 17) $Label22 = GUICtrlCreateLabel("- SPERIA-2", 216, 178, 61, 17) $Label23 = GUICtrlCreateLabel("- SP-102-5", 216, 194, 57, 17) $Label24 = GUICtrlCreateLabel("- SP-102-1", 216, 210, 57, 17) $Label25 = GUICtrlCreateLabel("- SP-102-4", 216, 226, 57, 17) $Label26 = GUICtrlCreateLabel("- SP-102-2", 216, 242, 57, 17) $Label27 = GUICtrlCreateLabel("- SP-102-3", 216, 258, 57, 17) $Label28 = GUICtrlCreateLabel("- SP-102-6", 216, 274, 57, 17) $Label29 = GUICtrlCreateLabel("- EASY", 216, 290, 41, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("COLAGEM", 312, 64, 145, 265) $Check25 = GUICtrlCreateCheckbox("261", 328, 80, 39, 17) $Check26 = GUICtrlCreateCheckbox("704", 328, 96, 39, 17) $Check27 = GUICtrlCreateCheckbox("264", 328, 112, 39, 17) $Check28 = GUICtrlCreateCheckbox("263", 328, 128, 39, 17) $Check29 = GUICtrlCreateCheckbox("262", 328, 144, 39, 17) $Check30 = GUICtrlCreateCheckbox("705", 328, 160, 39, 17) $Check31 = GUICtrlCreateCheckbox("421", 328, 176, 39, 17) $Check32 = GUICtrlCreateCheckbox("420", 328, 192, 39, 17) $Check33 = GUICtrlCreateCheckbox("258", 328, 208, 39, 17) $Check34 = GUICtrlCreateCheckbox("253", 328, 224, 39, 17) $Check35 = GUICtrlCreateCheckbox("255", 328, 240, 39, 17) $Check36 = GUICtrlCreateCheckbox("251", 328, 256, 39, 17) $Check37 = GUICtrlCreateCheckbox("252", 328, 272, 39, 17) $Label31 = GUICtrlCreateLabel("- EXPERT-3", 368, 82, 65, 17) $Label32 = GUICtrlCreateLabel("- EXPERT-5", 368, 98, 65, 17) $Label33 = GUICtrlCreateLabel("- EXPERT-1", 368, 114, 65, 17) $Label34 = GUICtrlCreateLabel("- EXPERT-2", 368, 130, 65, 17) $Label35 = GUICtrlCreateLabel("- EXPERT-4", 368, 146, 65, 17) $Label36 = GUICtrlCreateLabel("- EXPERT-6", 368, 162, 65, 17) $Label37 = GUICtrlCreateLabel("- AM-105-1", 368, 178, 59, 17) $Label38 = GUICtrlCreateLabel("- AM-105-2", 368, 194, 59, 17) $Label39 = GUICtrlCreateLabel("- MD-100-1", 368, 210, 60, 17) $Label40 = GUICtrlCreateLabel("- MD-68-1", 368, 226, 54, 17) $Label41 = GUICtrlCreateLabel("- MD-45-1", 368, 242, 54, 17) $Label47 = GUICtrlCreateLabel("- RICALL", 368, 258, 50, 17) $Label49 = GUICtrlCreateLabel("- BABY", 368, 274, 41, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group4 = GUICtrlCreateGroup("HOT-STAMP", 464, 64, 145, 89) $Check38 = GUICtrlCreateCheckbox("230", 480, 80, 39, 17) $Check39 = GUICtrlCreateCheckbox("424", 480, 96, 39, 17) $Check40 = GUICtrlCreateCheckbox("425", 480, 112, 39, 17) $Label42 = GUICtrlCreateLabel("- STEUER", 520, 82, 57, 17) $Label43 = GUICtrlCreateLabel("- FURNAX-HS", 520, 98, 75, 17) $Label44 = GUICtrlCreateLabel("- FURNAX-HS-2", 520, 114, 84, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group5 = GUICtrlCreateGroup("VERNIZ", 464, 152, 145, 89) $Check41 = GUICtrlCreateCheckbox("291", 480, 168, 39, 17) $Check42 = GUICtrlCreateCheckbox("290", 480, 184, 39, 17) $Label45 = GUICtrlCreateLabel("- VERCAL-1", 520, 170, 64, 17) $Label46 = GUICtrlCreateLabel("- VERCAL-2", 520, 186, 64, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group6 = GUICtrlCreateGroup("MANUTENÇÃO", 464, 240, 145, 89) $Check43 = GUICtrlCreateCheckbox("MICRO0177", 480, 256, 80, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $iEnd = GUICtrlCreateDummy() $ButtonUpdate = GUICtrlCreateButton("Atualizar", 464, 10, 147, 35) $ButtonCleanSel = GUICtrlCreateButton("Limpar seleção", 180, 27, 80, 25) GUICtrlSetState($ButtonCleanSel, $GUI_DISABLE); ###################################################### HABILITAR BOTÃO DE LIMPAR SELEÇÃO SÓ QUANDO ATUALIZAR TODOS NÃO ESTIVER SELECIONADO E NENHUMA SELEÇÃO FEITA GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $Shell = "PinShell" $PUUFile = "PUU.dat" $PUUPath = "M:\vm2\" & $Shell & "\" & $Shell & "\" $PUU = $PUUPath & $PUUFile ;~ local CheckStatus() CheckStatus() While 1 CheckStatus() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MenuItem4 Exit Case $MenuItem3 Run ( "notepad.exe " & $PUUFile, $PUUPath) Case $RadioUpdAll For $i = $iStart To $iEnd GUICtrlSetState($i, $GUI_DISABLE) Next ;~ IniWrite($PUU, "MTU Selection", "ALL", "1") Case $RadioUpdSel For $i = $iStart To $iEnd GUICtrlSetState($i, $GUI_ENABLE) Next Case $ButtonUpdate If GUICtrlRead($RadioUpdAll) = 1 Then IniWrite($PUU, "MTU Selection", "ALL", "1") If IniRead($PUU, "MTU Selection", "ALL", "") = 1 Then MsgBox(64, "Informação", "Definida atualização geral automatica.") EndIf ElseIf GUICtrlRead($RadioUpdSel) = 1 Then For $1 = 0 To 44 ; ######################################### ALTERAR NÚMERO DE ACORDO COM AS CHECKBOXES (MÁQUINAS) EXISTENTES If GUICtrlRead(Eval('Check' & $1)) = 1 Then IniWrite($PUU, "MTU Selection", GUICtrlRead(Eval('Check' & $1), 1), "1") If GUICtrlRead(Eval('Check' & $1)) <> 1 Then IniWrite($PUU, "MTU Selection", GUICtrlRead(Eval('Check' & $1), 1), "0") Next IniWrite($PUU, "MTU Selection", "ALL", "0") If IniRead($PUU, "MTU Selection", "ALL", "") = 0 Then MsgBox(64, "Informação", "Definidos micros para atualizar automaticamente.") EndIf EndIf EndSwitch WEnd Func CheckStatus() For $1 = 0 To 44 ; ######################################### ALTERAR NÚMERO DE ACORDO COM AS CHECKBOXES (MÁQUINAS) EXISTENTES If IniRead($PUU, "MTU Selection", GUICtrlRead(Eval('Check' & $1), 1), "") = 1 Then GUICtrlSetState(Eval('Check' & $1), $GUI_CHECKED) Next For $1 = 0 To 44 ; ######################################### ALTERAR NÚMERO DE ACORDO COM AS CHECKBOXES (MÁQUINAS) EXISTENTES If IniRead($PUU, "MTU Selection", GUICtrlRead(Eval('Check' & $1), 1), "") = "A" Then DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", Eval('Check' & $1), "wstr", 0, "wstr", 0) GUICtrlSetBkColor(Eval('Check' & $1), $COLOR_GREEN) EndIf Next For $1 = 0 To 44 ; ######################################### ALTERAR NÚMERO DE ACORDO COM AS CHECKBOXES (MÁQUINAS) EXISTENTES If IniRead($PUU, "MTU Selection", GUICtrlRead(Eval('Check' & $1), 1), "") = "N" Then DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", Eval('Check' & $1), "wstr", 0, "wstr", 0) GUICtrlSetBkColor(Eval('Check' & $1), $COLOR_RED) EndIf Next If IniRead($PUU, "MTU Selection", "ALL", "") = 1 Then GUICtrlSetState($RadioUpdAll, $GUI_CHECKED) For $i = $iStart To $iEnd GUICtrlSetState($i, $GUI_DISABLE) Next Else GUICtrlSetState($RadioUpdSel, $GUI_CHECKED) For $i = $iStart To $iEnd GUICtrlSetState($i, $GUI_ENABLE) Next EndIf EndFunc Edited March 21, 2019 by pintas Link to comment Share on other sites More sharing options...
Nine Posted March 21, 2019 Share Posted March 21, 2019 The function CheckStatus () is called every time in the main loop and its code is executed repeatedly even if there is no change. So you need to find a way to detect a change and execute the function only when the change happens. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pintas Posted March 21, 2019 Author Share Posted March 21, 2019 21 minutes ago, Nine said: The function CheckStatus () is called every time in the main loop and its code is executed repeatedly even if there is no change. So you need to find a way to detect a change and execute the function only when the change happens. Thanks for replying so quickly. That makes perfect sense, i just don't understand the logic in how to monitor the changes of an ini file. Link to comment Share on other sites More sharing options...
Nine Posted March 21, 2019 Share Posted March 21, 2019 (edited) You could make a copy of the ini file and compare both files. If they are identical then don't execute the function. When the original file gets modified, you replace the copy file...you should do that comparaison every 10 secs or something alike... Edited March 21, 2019 by Nine pintas 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pintas Posted March 21, 2019 Author Share Posted March 21, 2019 Why didn't i think of that sooner? ☺️ Thanks @Nine! Link to comment Share on other sites More sharing options...
Nine Posted March 21, 2019 Share Posted March 21, 2019 Just now, pintas said: Why didn't i think of that sooner? ☺️ Thanks @Nine! You could also take a look at FileGetTime and FileGetSize. Those function could also be used to check changes... Enjoy ! pintas 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pintas Posted March 21, 2019 Author Share Posted March 21, 2019 1 hour ago, Nine said: You could also take a look at FileGetTime and FileGetSize. Those function could also be used to check changes... Enjoy ! Perfect. Thanks again! Link to comment Share on other sites More sharing options...
AdamUL Posted March 27, 2019 Share Posted March 27, 2019 (edited) You can also check the file hashes of the files, if they are the same, the file is the same. Here is a function to do that. #include <Crypt.au3> Func _SameFilesHashes($sTestFile1, $sTestFile2) ;Returns True if the same file hash, and False if they are not or an error occures. ;Get SHA1 hashes of the old and new files. _Crypt_Startup() Local $sFileHash1 = _Crypt_HashFile($sTestFile1, $CALG_SHA1) Local $iHashError1 = @error Local $sFileHash2 = _Crypt_HashFile($sTestFile2, $CALG_SHA1) Local $iHashError2 = @error _Crypt_Shutdown() ;Compare the hashes to see if they are the same, and check for errors. Select Case $sFileHash1 == $sFileHash2 And Not $iHashError1 And Not $iHashError2 Return True Case $iHashError1 Return SetError(1, $iHashError1, False) Case $iHashError2 Return SetError(2, $iHashError2, False) Case Else Return False EndSelect EndFunc Adam Edited March 27, 2019 by AdamUL pintas 1 Link to comment Share on other sites More sharing options...
pintas Posted March 29, 2019 Author Share Posted March 29, 2019 On 3/27/2019 at 3:07 PM, AdamUL said: You can also check the file hashes of the files, if they are the same, the file is the same. Here is a function to do that. #include <Crypt.au3> Func _SameFilesHashes($sTestFile1, $sTestFile2) ;Returns True if the same file hash, and False if they are not or an error occures. ;Get SHA1 hashes of the old and new files. _Crypt_Startup() Local $sFileHash1 = _Crypt_HashFile($sTestFile1, $CALG_SHA1) Local $iHashError1 = @error Local $sFileHash2 = _Crypt_HashFile($sTestFile2, $CALG_SHA1) Local $iHashError2 = @error _Crypt_Shutdown() ;Compare the hashes to see if they are the same, and check for errors. Select Case $sFileHash1 == $sFileHash2 And Not $iHashError1 And Not $iHashError2 Return True Case $iHashError1 Return SetError(1, $iHashError1, False) Case $iHashError2 Return SetError(2, $iHashError2, False) Case Else Return False EndSelect EndFunc Very nice. Forgot about it. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now