Jump to content

Program for MediaPortal. Can't find filepath


Recommended Posts

I have a problem with a script and I doesn't seem to be able to find the error.

I'm making a HTPC and I'm installing MediaPortal on it. There are some plugins that can start a program, but it has some bugs and therefor I wanted to make my own.

What the script does.

Checks for mediaportal exe and the external program exe.

If found, it shuts down mediaportal and runs the external program

When the external program is no longer running, mediaportal is restarted.

Seems easy enough..

Im loading the filenames and window names (for closing) from an .ini file.

In the beginning of the script, I get the filename for mediaportal and $_mpdir is the correct path, but when I start Mediaportal and then run the first function "If Not FileExists($_mpdir)" the $_mpdir is "error". For some reason it cant see the correct path anymore.

The code

Opt("WinTitleMatchMode", -1)
Global $filename = StringSplit(@ScriptName, ".")
Global $_mpdir = IniRead($filename[1] & ".ini", "MEDIAPORTAL", "wdir", "error")
Global $_wname = IniRead($filename[1] & ".ini", "MEDIAPORTAL", "wname", "error") ;= WinGetTitle("[active]") 
Global $_rundir = IniRead($filename[1] & ".ini", "RUN", "rdir", "error")
Global $_rname = IniRead($filename[1] & ".ini", "RUN", "rname", "error")
Global $runmp

HotKeySet("{F11}", "Runme")

Runme()

Func Runme()
If Not FileExists($_mpdir) Then
    MsgBox(16, "Error", $_mpdir & " could not be found. Check the ini file for errors!")
    Exit
ElseIf Not FileExists($_rundir) Then
    MsgBox(16, "Error", $_rundir & " could not be found. Check the ini file for errors!")
    Exit
ElseIf Not WinExists($_wname) Then
    MsgBox(16, "error", "A running Mediaportal could not be found" & $_wname)
    Exit
Else
    MsgBox(0,"", $filename[1] & " " & $_wname)
    WinClose($_wname)
    WinWaitClose($_wname, "", 5)
    Run($_rundir)
    Sleep (2000)
    Cases()
EndIf
EndFunc

Func Cases()
    While 1
        Select
        Case WinExists($_rname)
            $runmp = 0
            Sleep (2000)
        Case $runmp = 1 And Not WinExists($_wname)
            Run($_mpdir)
            WinWait($_wname)
;~          WinActivate($_wname)
            Exit
        Case Not WinExists($_rname)
            $runmp = 1
            Sleep (2000)

    EndSelect
;~  MsgBox(16, "error", $runmp & " " & $_rname & " " & $_wname)
    WEnd
EndFunc

The INI file. The exe files exists

[MEDIAPORTAL]
wdir = "D:\MediaPortal\MediaPortal.exe"
wname = "MediaPortal"

[RUN]
rdir = "D:\WinTrack8\track.exe"
rname = "WinTrack"
Edited by Hest
Software:Model Train Calculator (Screen)Autoit3 beginner!
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...