Jump to content

FileOpen sometimes stops working


Flash
 Share

Recommended Posts

Hello,

a while ago I made myself an application to periodically check a website for changes. Changes are then stored into a file on my computer for me to check them later. Actions are logged into a textfile. I started coding under Win 8.1 and from the start had a weird error that I could not track down. In my GUI I have a tab for the log file to be displayed and that sometimes did not work after some time until I restarted the program. For me this issue wasn't big enough to do the fixing. Then I changed to Win10. Not only after some time the log was not displayed but also sometimes immidiately after startup. Also the file that is created for a change on the website (each change another file) was sometimes not. So whenever the log wasn't displayed anymore, also creating of the other files would not work anymore. Trying to find a solution I found out, that FileOpen would simply not work anymore. It returns the error code -1 and thats it, I have no idea why. The files are not opened in any oher program. Nvm, I found a "solution": Adding #requireAdmin to the script fixed all my problems, but created a new one (couldn't auto start on system boot).

Also I tried:

Closing Malwarebytes Anti-Malware -> no effect (no other anti virus installed)

Giving the executable of my app all rights within the folder (the version without admin rights) -> no effect

Using different folder locations (also Desktop) -> no effect

Using different autoit versions -> no effect

 

Some other info:

UAC is turned off

Win 10 Pro 64bit

Latest stable autoit 3.3.12

 

Anyone having any ideas what could cause theis kind of problem for FileOpen not to work anymore?

 

Thanks

 

Edited by Flash
Link to comment
Share on other sites

Hey, sorry for my late answer.

I cannot post all the code, cause I'm using some parts from someone else who doesn't want it to be published.

 

However, these are the parts that are relevant:

Creating info file:

Func _createInfoFile($URL, $name, $name1, $name2, $language, $debug = 0)
    Local $file = $name & ".data"

    Local $fileString = "[Name] = " & $name & @CRLF & _
            "[Name1] = " & $name1 & @CRLF & _
            "[Name2] = " & $name2 & @CRLF & _
            "[Language] = " & $language & @CRLF & _
            "[URL] = " & $URL


    Local $hFile = FileOpen($file, 2 + 8) ;overwrite + create dir structure
    If $debug = 1 Then MsgBox(0, "Logdatei", $hFile & @CRLF & @error & @CRLF & @extended)

    FileWrite($hFile, $fileString)
    FileClose($hFile)

EndFunc

Log:

Global $logFileName = "log\{year}_{month}_{day}.log"


Func _Log($data, $tabs = 0, $returns = 0)
    If $tabs < 0 Then $tabs = 0

    Local $tabString = " - ", $_msg

    For $i = 1 To $tabs
        $tabString &= "      "
    Next

    If $data = "" Then
        $_msg = ""
    Else
        Local $_date = @YEAR & "-" & @MON & "-" & @MDAY
        Local $_time = @HOUR & ":" & @MIN & ":" & @SEC
        If $data = " " Then $tabString = ""

        $_msg = $_date & "   " & $_time & $tabString & $data
    EndIf


    $hFileOpen = FileOpen(@ScriptDir & "\" & _getLogFileName(), 1)

    FileWriteLine($hFileOpen, $_msg)

    FileClose($hFileOpen)

    If $hGUI <> "" And GUICtrlRead($hTab) = $tabLog Then _updateLog()

EndFunc   ;==>_Log


Func _updateLog($logFile = _getLogFileName(), $debug = 0)

    Local $file = FileRead($logFile)
    If $debug = 1 Then MsgBox(0, "Logdatei", $file & @CRLF & @error & @CRLF & @extended)

    Local $setData = GUICtrlSetData($hLog, $file)
    ;If $debug = 1 Then MsgBox(0, "Set Data", $setData & @CRLF & @error & @CRLF & @extended)
    ;_GUICtrlEdit_SetText($hLog, $logText)

    Local $textLength = _GUICtrlEdit_GetTextLen($hLog)
    ;If $debug = 1 Then MsgBox(0, "Textlänge", $textLength & @CRLF & @error & @CRLF & @extended)

    Local $selection = _GUICtrlEdit_SetSel($hLog, $textLength, $textLength)
    ;If $debug = 1 Then MsgBox(0, "Set Selection", $selection & @CRLF & @error & @CRLF & @extended)

    Local $scroll = _GUICtrlEdit_Scroll($hLog, $SB_SCROLLCARET)
    ;If $debug = 1 Then MsgBox(0, "Scrollen ans Ende", $scroll & @CRLF & @error & @CRLF & @extended)
EndFunc   ;==>_updateLog


Func _getLogFileName()
    Local $logFile = StringReplace($logFileName, "{year}", @YEAR)
    $logFile = StringReplace($logFile, "{month}", @MON)
    $logFile = StringReplace($logFile, "{day}", @MDAY)

    Return $logFile
EndFunc   ;==>_getLogFileName

These are the only parts where the  files are accessed to. The info files are opened manually by me afterwards for now.

 

The main process runs every 15 minutes logging all activities using _Log() and creates an info file in case of finding new data for every new data found.

Edited by Flash
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...