Jump to content

ProcessExists stops working?


Recommended Posts

Well it happened. I don't know what to make of it though.

lDkbgXy.png

 

Edit: So I forgot to check the memory usage before I closed it, but luckily I was running it on two different computers (and it died on both). And.. wow. The memory usage was at 3.7GB! Now I'm no real smart guy, but I'll bet that has something to do with the functions messing up. Now I just need to figure out where my code is going wrong to rack up that much memory.

Edited by therks
Link to comment
Share on other sites

Your code isn't using the memory, the Java process is, AutoIt is only using 748K. Also, that screenshot shows only .425Gb memory used.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Sorry, I wasn't clear. When I said I forgot to check the memory usage, I also meant in that screenshot I didn't actually get the process of my script on screen (that AutoIt process is something else, my script was actually named server_wrapper.exe), and I didn't think to screenshot the other computer, where I actually saw my script in the task manager WAS using a tonne of memory.

Oh! Before I forget again... My brother pointed out an important point I keep forgetting to communicate, the script I'm running is 32 bit due to a UDF I'm using that isn't compatible with 64 bit. He pointed out that a 32 bit application probably can't even use so much memory and that's why I'm getting the weird glitches (or at least, it's certainly not helping).

Edited by therks
Link to comment
Share on other sites

  • Developers

You might also want to check the Autoit3 process information with Process Explorer to figure out whether it is consuming too many handles or or anomalies.

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks for the advice Jos. Unfortunately I'm not really sure what is normal with this information. This is a screencap of it now though (it's been running for about 14 hours, no issues so far), does anything look glaringly out of the ordinary?

y4hQCxd.png

Edit: Page faults are bad right? I'm not seeing that number so high in my other AutoIt programs. Time for some trial and error...

Edit #2: Well I know where the page faults are coming from, it's just from the ProcessExists function itself. I tried this test script:

$iPID = Run(@ComSpec)

While ProcessExists($iPID)
WEnd

Then I checked Process Explorer and the Page Fault Delta was up over 700k.

Edited by therks
Link to comment
Share on other sites

  • Developers

I don't know what is normal either, but it seems that when it starts failing it isn't able anymore to do any Process* command  when looking at your logging.

It also seems the CPU Cycles is pretty high for this program!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Alrighty, so I was running another test case. I actually didn't have it launching the java server this time, just cmd.exe. I was trying to isolate if the problem was somehow coming from the java process, but it managed to glitch again in about 7 hours. The memory usage bounced around a lot, but when it actually glitched out, it was only around 400mb, so I'd guess that's not what's causing the problems. But as Jos suggested, I checked the handles, and it's way higher than normal.

zb7HLG8.png

I'm still not sure what makes it go off the rails, but I've managed to pare down the code to a wieldy size, so I'll post it here in case anyone is willing to get down and dirty.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=mcsw.ico
#AutoIt3Wrapper_Res_Description=MCSW
#AutoIt3Wrapper_Res_Fileversion=1.1.0.19
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=therks
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
If @AutoItX64 Then Exit 100 & MsgBox(0x30, 'Notice', 'This application cannot be 64-bit due to the 32bit 7zip functions')

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <GUIEdit.au3>
#include <WinAPI.au3>
#include <WinAPIShPath.au3>

#include "7zip_mod.au3"

Opt('MustDeclareVars', 1)
Opt('WinTitleMatchMode', 3)

Global Const $APP_NAME = 'Server Wrapper'
Global Const $INI_FILE = @ScriptDir & '\mcsw.ini'
Global Const $LOG_FILE = @ScriptDir & '\mcsw.log'
Global $hLogWrite
Global Const $SERVER_CMD = _IniReadRaw($INI_FILE, 'Config', 'Command', @ComSpec)
Global Const $SERVER_DIR = IniRead($INI_FILE, 'Config', 'Folder', 'c:\')
Global $HGUI_MAIN, $ED_LOG, $I_PID, $A_WINPOS = StringSplit(IniRead($INI_FILE, 'Config', 'Window', ''), '|', 2)

Global $S_ERROR = ''
If Not $SERVER_CMD Then $S_ERROR = 'Server command not defined.' & @LF
If Not $SERVER_DIR Then $S_ERROR &= 'Server folder not defined.' & @LF

If $S_ERROR Then
    MsgBox(0x10, $APP_NAME, $S_ERROR)
    Exit 200
EndIf


If $CmdLine[0] = 2 And $CmdLine[1] = '/compress' Then
    Exit 300 & _CompressBackups($CmdLine[2])
Else
    Main()
EndIf

Func Main()
    Local $sSinglerun = 'Singlerun mc_server_wrapper'
    If WinExists($sSinglerun) Then Exit 400 & ControlSetText('[LAST]', '', 'Edit1', 'Show')
    GUICreate($sSinglerun)
    Local $in_Interact = GUICtrlCreateInput('', -100, -100, 1, 1)

    If FileExists($LOG_FILE) Then
        FileMove($LOG_FILE, _WinAPI_PathYetAnotherMakeUniqueName(@ScriptDir & '\mcsw_' & FileGetTime($LOG_FILE, 0, 1) & '.log'))
    EndIf
    Global $hLogWrite = FileOpen($LOG_FILE, 1)
    If $hLogWrite = -1 Then
        MsgBox(0x10, $APP_NAME, 'Error: Unable to write to log file:' & @LF & $LOG_FILE)
        Exit 201
    EndIf
    OnAutoItExitRegister('_LogClose')

    Local $bMinNotice, $aInputHistory[255], $iHistoryIndex, _
        $sDiv = '****************************************************************************************************'

    #region - Build GUI

    Opt('GUICloseOnEsc', 0)
    Opt('TrayOnEventMode', 1)
    Opt('TrayMenuMode', 1+2)
    TraySetClick(16)
    TrayCreateItem('&Show')
        TrayItemSetOnEvent(-1, '_ShowWin')
        TrayItemSetState(-1, 512) ; $TRAY_DEFAULT
    TrayCreateItem('&Quit')
        TrayItemSetOnEvent(-1, '_ConfirmExit')
    TraySetState(1)
    _TrayAnimate()
    TraySetToolTip($APP_NAME)

    Local $in_Interact, $dm_HistUp, $dm_HistDn, $bt_Folder, $bt_ServLog, $bt_Backup, $bt_Clear, $bt_Quit, $in_Command, $bt_Enter, $aGM

    GUIRegisterMsg($WM_MOVE, 'WM_SIZEMOVE')
    GUIRegisterMsg($WM_SIZE, 'WM_SIZEMOVE')

    $HGUI_MAIN = GUICreate($APP_NAME, 500, 320, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX))
        GUISetFont(Default, Default, Default, 'Lucida Console')
    $dm_HistUp = GUICtrlCreateDummy()
    $dm_HistDn = GUICtrlCreateDummy()

    Opt('GUIResizeMode', $GUI_DOCKSIZE + $GUI_DOCKLEFT + $GUI_DOCKTOP)
    $bt_Folder = GUICtrlCreateButton('&Folder', 0, 0, 80, 20)
    $bt_ServLog = GUICtrlCreateButton('Server &Log', 80, 0, 80, 20)
    $bt_Backup = GUICtrlCreateButton('&Backup Now', 160, 0, 80, 20)

    Opt('GUIResizeMode', $GUI_DOCKSIZE + $GUI_DOCKRIGHT + $GUI_DOCKTOP)
    $bt_Clear = GUICtrlCreateButton('&Clear', 340, 0, 80, 20)
    $bt_Quit = GUICtrlCreateButton('&Quit', 420, 0, 80, 20)

    $ED_LOG = GUICtrlCreateEdit('', 0, 20, 500, 280, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
        GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
        _GUICtrlEdit_SetLimitText($ED_LOG, 0x7fffffff)
    $in_Command = GUICtrlCreateInput('', 0, 300, 480, 20)
        GUICtrlSetResizing(-1, $GUI_DOCKSTATEBAR + $GUI_DOCKLEFT + $GUI_DOCKRIGHT)
    $bt_Enter = GUICtrlCreateButton('>', 480, 300, 20, 20)
        GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM)
        GUICtrlSetState(-1, $GUI_DEFBUTTON)

    #endregion - Build GUI

    Local $aAccel[][] = [ [ '{up}', $dm_HistUp ], [ '{down}', $dm_HistDn ] ]

    If $CmdLine[0] And $CmdLine[1] = '/hide' Then
        $bMinNotice = True
    Else
        _ShowWin()
    EndIf

    GUICtrlSetState($in_Command, $GUI_FOCUS)

    _CompressBackups_Check()
    AdlibRegister('_CompressBackups_Check', 6e5) ; 10 minutes

    Local $sLastPID, $iLastPID = IniRead($INI_FILE, 'Config', 'PID', 0)
    If ProcessExists($iLastPID) Then
        Local $aProcessList = ProcessList()
        If Not @error Then
            For $i = 1 To $aProcessList[0][0]
                If $aProcessList[$i][1] = $iLastPID Then
                    $sLastPID = @LF & 'Process Name: ' & $aProcessList[$i][0]
                    ExitLoop
                EndIf
            Next
        EndIf

        Do
            Local $iKillProc = MsgBox(0x223, 'Notice', 'It appears the server was not shutdown properly' & @LF & _
                'and the last process ID is currently active.' & @LF & @LF & _
                'Close this process?' & @LF & 'Process ID: ' & $iLastPID & $sLastPID)
            If $iKillProc = 6 Then ; Yes: 6, No: 7, Cancel: 2
                ProcessClose($iLastPID)
            EndIf
        Until $iKillProc <> 2
    EndIf

    Local $sServerOut, $aServerRead, $iRelaunchCount, $iRelaunchTimer, $iFocusCtrl, $sDateTrack = _TimeStamp(True), _
        $USER, $CMD, $PARAMS, $PARAM_EX, $SAVE_POS

    _LogWrite($sDateTrack & ' - Starting ' & $APP_NAME & ' v' & FileGetVersion(@ScriptFullPath))
    _Launch()
    OnAutoItExitRegister('_OnExit')

    Local $iMemReportTimer = TimerInit(), $aMemStats

    While 1
        #region - DEBUGGING ============================================================================================
        If TimerDiff($iMemReportTimer) > 3e5 Then ; 15 minutes
            $aMemStats = ProcessGetStats()
            If Not @error Then
                _LogWrite('MemReport: ' & StringRegExpReplace($aMemStats[0], '(\d)(?=(\d{3})+$)', '\1,'))
            EndIf
            $iMemReportTimer = TimerInit()
        EndIf
        #endregion - DEBUGGING ============================================================================================

        If GUICtrlRead($in_Interact) = 'Show' Then
            _ShowWin()
            GUICtrlSetData($in_Interact, '')
        EndIf

        _Backup()
        If $iFocusCtrl = $in_Command Then
            If _WinAPI_GetFocus() <> GUICtrlGetHandle($in_Command) Then
                GUISetAccelerators(0)
                $iFocusCtrl = 0
            EndIf
        Else
            If _WinAPI_GetFocus() = GUICtrlGetHandle($in_Command) Then
                GUISetAccelerators($aAccel)
                $iFocusCtrl = $in_Command
            EndIf
        EndIf

        If $sDateTrack <> _TimeStamp(True) Then ; Log the date when it changes at midnight
            $sDateTrack = _TimeStamp(True)
            _LogWrite($sDateTrack)
        EndIf

        If Not ProcessExists($I_PID) Then
            _LogWrite('Process lost: ' & $I_PID)
            StdioClose($I_PID)

            If TimerDiff($iRelaunchTimer) < 5000 Then
                $iRelaunchCount += 1
            Else
                $iRelaunchCount = 1
            EndIf

            If $iRelaunchCount <= 5 Then
                _LogWrite($sDiv & @CRLF, 1)
                _LogWrite('Relaunching... (attempt ' & $iRelaunchCount & ')')
                _Launch()
            Else
                GUISetState(@SW_SHOW)
                Local $sRelaunchExceeded = 'Relaunch looped ' & $iRelaunchCount-1 & ' times in ' & Round(TimerDiff($iRelaunchTimer)/1000) & ' seconds.'
                _LogWrite($sRelaunchExceeded)
                If MsgBox(0x115, $APP_NAME, $sRelaunchExceeded & @LF & 'Ensure that server is not already running.' & @LF & 'Would you like to continue trying?') = 2 Then; Retry: 4, Cancel: 2
                    _LogWrite('Exiting')
                    ExitLoop
                Else
                    _LogWrite('Retrying.')
                    $iRelaunchCount = 1
                    _LogWrite($sDiv & @CRLF, 1)
                    _LogWrite('Relaunching... (attempt ' & $iRelaunchCount & ')')
                    _Launch()
                EndIf
            EndIf
            $iRelaunchTimer = TimerInit()
        Else
            If _GUICtrlEdit_GetLineCount($ED_LOG) > 1000 Then
                Local $iLineCount = _GUICtrlEdit_GetLineCount($ED_LOG)-1000
                _GUICtrlEdit_BeginUpdate($ED_LOG)
                _GUICtrlEdit_SetText($ED_LOG, StringTrimLeft(GUICtrlRead($ED_LOG), _GUICtrlEdit_LineIndex($ED_LOG, $iLineCount)))
                _GUICtrlEdit_LineScroll($ED_LOG, 0, _GUICtrlEdit_GetLineCount($ED_LOG))
                _GUICtrlEdit_EndUpdate($ED_LOG)
            EndIf

            $sServerOut = StdoutRead($I_PID)
            If $sServerOut Then
                _TrayAnimate()
                _LogWrite($sServerOut & @CRLF, 1)
                TraySetToolTip('Last activity: ' & @LF & StringRegExpReplace($sServerOut, '\[(\d\d:\d\d:\d\d)\].*', '\1'))
            EndIf

            $aGM = GUIGetMsg(1)
            Switch $aGM[0]
                Case $bt_Enter
                    Local $sReadCmd = GUICtrlRead($in_Command)
                    If $sReadCmd Then
                        If $sReadCmd = 'quit' Or $sReadCmd = 'exit' Then
                            ExitLoop
                        ElseIf $sReadCmd = 'clear' Or $sReadCmd = 'cls' Then
                            GUICtrlSetData($ED_LOG, '')
                        ElseIf $sReadCmd = 'backup' Then
                            If $aInputHistory[0] <> $sReadCmd Then _ArrayPush($aInputHistory, $sReadCmd, 1)
                            _LogWrite(@CRLF & '>' & $sReadCmd & @CRLF, 1)
                            _Backup(True)
                        ElseIf $sReadCmd Then
                            _LogWrite(@CRLF & '>' & $sReadCmd & @CRLF, 1)
                            If $sReadCmd = 'help' Or $sReadCmd = '?' Then
                                _LogWrite('--- Wrapper commands: ---')
                                _LogWrite('quit | exit : Stop server and exit wrapper')
                                _LogWrite('backup : Perform immediate backup of server files')
                                _LogWrite('clear | cls : Clears wrapper log window' & @CRLF)
                            EndIf
                            StdinWrite($I_PID, $sReadCmd & @CRLF)
                        EndIf
                        $iHistoryIndex = -1
                        If $aInputHistory[0] <> $sReadCmd Then _ArrayPush($aInputHistory, $sReadCmd, 1)
                        GUICtrlSetData($in_Command, '')
                    EndIf
                    GUICtrlSetState($in_Command, $GUI_FOCUS)
                Case $dm_HistUp
                    $iHistoryIndex += 1
                    If $iHistoryIndex < UBound($aInputHistory) And $aInputHistory[$iHistoryIndex] Then
                        GUICtrlSetData($in_Command, $aInputHistory[$iHistoryIndex])
                    Else
                        $iHistoryIndex -= 1
                    EndIf
                Case $dm_HistDn
                    $iHistoryIndex -= 1
                    If $iHistoryIndex >= 0 And $aInputHistory[$iHistoryIndex] Then
                        GUICtrlSetData($in_Command, $aInputHistory[$iHistoryIndex])
                    Else
                        $iHistoryIndex = -1
                        GUICtrlSetData($in_Command, '')
                    EndIf
                Case $bt_Folder
                    ShellExecute($SERVER_DIR)
                    GUICtrlSetState($in_Command, $GUI_FOCUS)
                Case $bt_ServLog
                    ShellExecute($SERVER_DIR & '\logs\latest.log')
                    GUICtrlSetState($in_Command, $GUI_FOCUS)
                Case $bt_Backup
                    _Backup(True)
                    GUICtrlSetState($in_Command, $GUI_FOCUS)
                Case $bt_Clear
                    GUICtrlSetData($ED_LOG, '')
                    GUICtrlSetState($in_Command, $GUI_FOCUS)
                Case $bt_Quit
                    _ConfirmExit()
                    GUICtrlSetState($in_Command, $GUI_FOCUS)
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE)
                    If Not $bMinNotice Then
                        $bMinNotice = True
                        TrayTip($APP_NAME, 'Window minimized to tray.' & @LF & 'To start in the tray, run with /hide parameter.' & @LF & 'ie: ' & @ScriptName & ' /hide', 3, 1)
                    EndIf
            EndSwitch
        EndIf
    WEnd
EndFunc


Func _ShowWin()
    If UBound($A_WINPOS) = 5 Then
        Local $bMaximize
        If $A_WINPOS[4] = 1 Then $bMaximize = True

        GUISetState(@SW_SHOWNA)
        WinMove($HGUI_MAIN, '', $A_WINPOS[0], $A_WINPOS[1], $A_WINPOS[2], $A_WINPOS[3])
        If $bMaximize Then
            GUISetState(@SW_MAXIMIZE)
        EndIf
    Else
        GUISetState(@SW_SHOWNA)
    EndIf
    WinActivate($HGUI_MAIN)
    _GUICtrlEdit_LineScroll($ED_LOG, 0, _GUICtrlEdit_GetLineCount($ED_LOG))
EndFunc

Func _ConfirmExit()
    If MsgBox(0x134, $APP_NAME, 'Are you sure you want to shutdown the server?', 0, $HGUI_MAIN) = 6 Then
        GUISetState(@SW_HIDE)
        Exit 500
    EndIf
EndFunc

Func _TimeStamp($bDate = False)
    If $bdate Then
        Return @YEAR &'-'& @MON &'-'& @MDAY
    Else
        Return '*[' & @HOUR & ':' & @MIN & ':' & @SEC & '] [Wrapper]: '
    EndIf
EndFunc

Func _Backup($bManual = false)
    ; DEBUGGING -- Disabled this function
    Return True

    Local $sTime, $sBackupFile, $sBackupCheck, $vLogTime, $sTimeFormat = '%04d-%02d-%02d_%02d.%02d.%02d'
    $sTime = StringFormat($sTimeFormat, @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC)
    $sBackupFile = $SERVER_DIR & '\backups\' & $sTime
    $sBackupCheck = $sBackupFile
    If Not $bManual Then
        $vLogTime = FileGetTime($SERVER_DIR & '\logs\latest.log')
        If UBound($vLogTime) = 6 Then
            $vLogTime = StringFormat($sTimeFormat, $vLogTime[0], $vLogTime[1], $vLogTime[2], $vLogTime[3], $vLogTime[4], $vLogTime[5])
            If _IsMoreRecentBackup($vLogTime) Then Return False
        EndIf

        $sBackupCheck = StringTrimRight($sBackupCheck, 8) & '*' ; Trim time (ie: 2001-02-03_04:05:06 = 2001-02-03_*)
    EndIf
    If Not FileExists($sBackupCheck) Then
        _LogWrite('Creating backup...')
        If DirCopy($SERVER_DIR & '\data', $sBackupFile & '~') Then
            DirMove($sBackupFile & '~', $sBackupFile)
            _LogWrite('Backup completed.')
            Return True
        Else
            _LogWrite('Backup failed.')
        EndIf
    EndIf
EndFunc

Func _IsMoreRecentBackup($sCompareTime)
    Local $sPath = $SERVER_DIR & '\backups\', $hSearch, $sFile, $sFileTime, $sReturnTime
    If FileExists($sPath) Then
        $hSearch = FileFindFirstFile($sPath & '*.zip')
        While $hSearch <> -1
            $sFile = FileFindNextFile($hSearch)
            If @error Then ExitLoop
            If $sFile > $sCompareTime Then Return True
        WEnd
        FileClose($hSearch)
    EndIf
EndFunc

Func _CompressBackups($sPath)
    Local $s7zipDll
    Do
        $s7zipDll = @TempDir & '\' & Hex(Random(1e9)) & '.dll'
    Until FileInstall('7-zip32.dll', $s7zipDll)

    _7ZipStartup($s7zipDll)
    Local $sSinglerun = 'Singlerun mc_server_wrapper compress'
    If WinExists($sSinglerun) Then Return 100
    GUICreate($sSinglerun)
    ProcessSetPriority(@AutoItPID, 0)

    Local $hSearch, $sFile
    If FileExists($sPath) Then
        $hSearch = FileFindFirstFile($sPath & '*')
        While $hSearch <> -1
            $sFile = FileFindNextFile($hSearch)
            If @error Then ExitLoop
            If StringInStr(FileGetAttrib($sPath & $sFile), 'D') And StringRight($sFile, 1) <> '~' And Not FileExists($sPath & $sFile & '.zip') Then
                _7ZipAdd(0, $sPath & $sFile & '.zip', $sPath & $sFile & '\*', 1, 9)
                DirRemove($sPath & $sFile, 1)
            EndIf
        WEnd
        FileClose($hSearch)
    EndIf
    Return 99

    _7ZipExitFunc() ; Unload dll manually
    FileDelete($s7zipDll)
EndFunc

Func _CompressBackups_Check()
    Local $sRunCommand = '"' & @AutoItExe & '" /compress "' & $SERVER_DIR & '\backups\"'
    If Not @Compiled Then
        $sRunCommand = '"' & @AutoItExe & '" "' & @ScriptFullPath & '" /compress "' & $SERVER_DIR & '\backups\"'
    EndIf

    Local $sPath = $SERVER_DIR & '\backups\'
    Local $hSearch, $sFile
    If FileExists($sPath) Then
        $hSearch = FileFindFirstFile($sPath & '*')
        While $hSearch <> -1
            $sFile = FileFindNextFile($hSearch)
            If @error Then ExitLoop
            If StringInStr(FileGetAttrib($sPath & $sFile), 'D') Then
                Run($sRunCommand)
                ExitLoop
            EndIf
        WEnd
        FileClose($hSearch)
    EndIf
    Return 99
EndFunc

Func _TrayAnimate()
    Global $S_TRAYICON
    If Not $S_TRAYICON Then
        $S_TRAYICON = @TempDir & '\'
        Do
            $S_TRAYICON &= Random(1, 9, 1)
        Until FileInstall('mcsw.icl', $S_TRAYICON)
        OnAutoItExitRegister(_TrayAnimate_Cleanup)
    EndIf

    _TrayAnimate_Active()
    AdlibRegister(_TrayAnimate_Inactive, 2000)
EndFunc

Func _TrayAnimate_Active()
    Global $S_TRAYICON
    Static $iFrame = 5
    $iFrame = ($iFrame < 8) ? $iFrame + 1 : 5
    TraySetIcon($S_TRAYICON, $iFrame)
    AdlibRegister(_TrayAnimate_Active, 100)
EndFunc

Func _TrayAnimate_Inactive()
    Global $S_TRAYICON
    Static $iFrame = 1
    AdlibUnRegister(_TrayAnimate_Active)
    $iFrame = ($iFrame < 4) ? $iFrame + 1 : 1
    TraySetIcon($S_TRAYICON, $iFrame)
    AdlibRegister(_TrayAnimate_Inactive, 500)
EndFunc

Func _TrayAnimate_Cleanup()
    Global $S_TRAYICON
    If $S_TRAYICON Then FileDelete($S_TRAYICON)
EndFunc

Func _Launch()
    Global $I_PID = Run($SERVER_CMD, $SERVER_DIR, @SW_HIDE, BitOR($STDIN_CHILD, $STDERR_MERGED))
    If @error Then
        MsgBox(0x10, $APP_NAME, 'Error running command:' & @LF & $SERVER_CMD & @LF & @LF & 'In directory:' & @LF & $SERVER_DIR) ; OK: 1
        Exit 600
    EndIf
    _LogWrite('Server launched (PID:' & $I_PID & ').')
    IniWrite($INI_FILE, 'Config', 'PID', $I_PID)
EndFunc

Func _IniReadRaw($sFile, $sSection, $sKey, $sDefault = '')
    Local $f, $t = IniReadSection($sFile, $sSection)
    If @error Then
        Return SetError(@error, 0, $sDefault)
    Else
        For $i = 1 to $t[0][0]
            If $t[$i][0] = $sKey Then
                Return SetExtended($i, $t[$i][1])
            EndIf
        Next
    EndIf
    Return SetExtended(-1, $sDefault)
EndFunc

Func _OnExit()
    If UBound($A_WINPOS) = 5 Then
        IniWrite($INI_FILE, 'Config', 'Window', $A_WINPOS[0] &'|'& $A_WINPOS[1] &'|'& $A_WINPOS[2] &'|'& $A_WINPOS[3] &'|'& $A_WINPOS[4])
    EndIf

    If ProcessExists($I_PID) Then
        _LogWrite('Stopping server...')
        StdinWrite($I_PID, 'exit' & @CRLF)
        StdioClose($I_PID)
        If Not ProcessWaitClose($I_PID, 5) Then
            _LogWrite('Server process still running. Attempting forced end.')
            ProcessClose($I_PID)
            If Not ProcessWaitClose($I_PID, 5) Then
                _LogWrite('Unable to end process: ' & $I_PID)
            EndIf
        EndIf
    EndIf

    If Not ProcessExists($I_PID) Then $I_PID = 0
    IniWrite($INI_FILE, 'Config', 'PID', $I_PID)
EndFunc

Func _LogWrite($sText, $bNoFormat = 0)
    If Not $bNoFormat Then
        $sText = _TimeStamp() & $sText & @CRLF
    EndIf
    _GUICtrlEdit_AppendText($ED_LOG, $sText)
    FileWrite($hLogWrite, $sText)
EndFunc

Func _LogClose()
    FileClose($hLogWrite)
EndFunc

Func WM_SIZEMOVE($hWnd, $iMsg, $iWParam, $iLParam)
    If $hWnd = $HGUI_MAIN Then
        If Not BitAND(WinGetState($hWnd), 16 + 32) Then ; NOT Minimized OR Maximized
            $A_WINPOS = WinGetPos($hWnd)
            If IsArray($A_WINPOS) Then ReDim $A_WINPOS[5]
        ElseIf BitAND(WinGetState($hWnd), 32) Then ; Maximized
            If UBound($A_WINPOS) = 5 Then $A_WINPOS[4] = 1
        EndIf
    EndIf
EndFunc

Edit: Boy the forum interpreter kinda loses itself in the color coding eh? Is there something I can do to make that better for you guys?

Edit 2: Ok.. after my last edit it actually looks fine, so ignore that last comment.

Edit 3: Oh, I should probably attach that include file. It's a slight modification of a UDF by @rasim. His include loads the 7zip dll right away. Since I only use the 7zip functions in a spin off process, I modified his UDF so that I can manually load the dll when I choose to.

7Zip_mod.au3

Edited by therks
I'm scatterbrained...
Link to comment
Share on other sites

Oh gosh, so sorry, I should have mentioned (I swear I meant to make a note of this). So no, I have not yet seen the error with this latest code. I have it compiled, and it's currently running (it's been 2.5 hours), but as has been mentioned it takes a while before the glitch happens. If everyone wants to wait until I can definitively say this code causes the error then I absolutely understand, and in fact encourage that. The last thing I want to do is waste anybody's time.

Link to comment
Share on other sites

Holy crap I think I just found it..

Func _IsMoreRecentBackup($sCompareTime)
    Local $sPath = $SERVER_DIR & '\backups\', $hSearch, $sFile, $sFileTime, $sReturnTime
    If FileExists($sPath) Then
        $hSearch = FileFindFirstFile($sPath & '*.zip')
        While $hSearch <> -1
            $sFile = FileFindNextFile($hSearch)
            If @error Then ExitLoop
            If $sFile > $sCompareTime Then Return True
        WEnd
        FileClose($hSearch)
    EndIf
EndFunc

I just realized that this function is leaving open file handles. And it's called from the main loop. And you were right to hesitate John, the part of the code that calls this was disabled in the code I posted above, so running it (as I have been for the last ~20 hours) would produce no errors.

Gosh I feel like a complete heel. Time to correct, compile, and test.

Link to comment
Share on other sites

Good news, hope it was the issue.

Fixed function.

Func _IsMoreRecentBackup($sCompareTime)
    Local $sPath = $SERVER_DIR & '\backups\', $hSearch, $sFile, $sFileTime, $sReturnTime
    If FileExists($sPath) Then
        $hSearch = FileFindFirstFile($sPath & '*.zip')
        While $hSearch <> -1
            $sFile = FileFindNextFile($hSearch)
            If @error Then ExitLoop
            If $sFile > $sCompareTime Then 
                FileClose($hSearch)
                Return True
            EndIf    
        WEnd
        FileClose($hSearch)
    EndIf
EndFunc

 

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Oh yeah, that's one way to do it. I actually did it like this:

Func _IsMoreRecentBackup($sCompareTime)
    Local $bReturn = False, $sPath = $SERVER_DIR & '\backups\', $hSearch, $sFile
    If FileExists($sPath) Then
        $hSearch = FileFindFirstFile($sPath & '*.zip')
        While $hSearch <> -1
            $sFile = FileFindNextFile($hSearch)
            If @error Then ExitLoop
            If $sFile > $sCompareTime Then
                $bReturn = True
                ExitLoop
            EndIf
        WEnd
        FileClose($hSearch)
    EndIf
    Return $bReturn
EndFunc

 

Edited by therks
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...