TweakMonkey (advanced options page) 1.02 - 4/2/2007 [MM2+3]

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

The files should be associated with Windows Script Host.

I've not checked the code, but looking at the functionality the OfflineWorker stores various data which is then used to restore at the session when you start up again, and also performs the backup. This is done in a separate script file so that MM doesn't have to wait around whilst this is done.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

The OfflineWorker script's purpose is to do stuff that can only be done while MediaMonkey is closed, i.e. create a backup of the current configuration (which is only saved when MM is closing).

Looking at the code, the file association isn't used because "wscript" is called explicitly. So I don't know why the file itself opens. The only reason I can think of is that you're using some older version of TweakMonkey where the code isn't the same as the code last mentioned by Teknojnky.

Cheers
Steegy
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
martialartsguy
Posts: 312
Joined: Mon Apr 03, 2006 9:11 am
Location: Denver, CO

Post by martialartsguy »

Just checking in here - I loved TweakMonkey when I ran 2.5 - is it upgraded to 3.0 (I'm using 1127 here)? I don't want to load it up and have it crash anything, and I'm patient on any changes that need to be made, just checking (though anxious) :D
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

It works fine for me in 3.0.. try it, if anything doesn't work just post and we can see whats up.
martialartsguy
Posts: 312
Joined: Mon Apr 03, 2006 9:11 am
Location: Denver, CO

Post by martialartsguy »

Hmm, guess I should have read the first post, eh?

Well, I did try it with my version (1127), and I got these errors when I tried to close down the options menu:


Image

and when I pushed OK:


Image

Thanks.
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

wierd, are you using the 1.02 version or an earlier one?

the only drop down on the script is on the tree node options, you might make sure that the drop down is not blank..

try check the 'node to be selected', select something from the drop down and see if the window will close.. you can uncheck it afterwards if you wish.
martialartsguy
Posts: 312
Joined: Mon Apr 03, 2006 9:11 am
Location: Denver, CO

Post by martialartsguy »

Teknojnky- Using 1.02 and it looks like the drop down selection fixed my error.


Thanks for the help and the awesome script!
PabloF

Moving database with TweakMonkey

Post by PabloF »

Hi all there. Sorry if I'm asking about something that was treated before, but I couldn't find any related post.

I've downloaded the new TweakMonkey version and, when tried to move the database (wich nowadays is called MM.DB), I get an error message stating that the database file MUST end with .MDB (by the way, I'm using MM3).

Any fix/woarkaround/thing I'm missing or misunderstanding?

Thanks in advance.

Pablo
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

Hmm, it was probly checking for MDB files to make sure it got the right one, but since mm3 uses .db file it probably needs updated.

You can work around by manually updating the mediamonkey.ini file (with MM closed) with

Code: Select all

[System]
DBName=C:\program files\mediamonkey3\MM3.db
obviously substitute your preferred database path and filename.

for mm3, the new default location for mediamonkey.ini and database @
Database location
Windows XP: C:\Documents and Settings\<USERNAME>\Local Settings\Application Data\MediaMonkey\MM.DB
Windows Vista: C:\Users\<USERNAME>\AppData\Local\MediaMonkey\MM.DB
PabloF

Post by PabloF »

Thank you, Teknojonky. I just wanted to avoid that, but, anyway... :)
The Crow
Posts: 44
Joined: Wed Nov 28, 2007 4:05 pm

Post by The Crow »

1. The search node reappears when using the search even if it has been disabled via Tweak Monkey before.
I don't think this can be changed as MM 3 creates the search node new every time and Tweak Monkey can only influence the start settings, or would it be possible to keep the search node off permanently?

By the way, the search node can't be disabled in MM standard settings either.

2. Strange behaviour: The function "Node to be selected at startup" doesn't really work with my MM 3. For a very short time the chosen node is selected when starting MM but then the node that was selected when leaving the last MM session gets marked again.
However when I change the language (doesn't matter which one) in MM settings, the "Node to be selected..." function works fine for the next session.
PabloF

Changing DB's location fails

Post by PabloF »

Hi Teknojnky. I followed your suggestion and tried to change the database location manually, without succes. I opened a new thread about this issue.

Thank you anyway.

Pablo
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

Here's more up to date code for MM3 only:

I didn't test it extensively because with new (+ changed) behaviour in MM3, this script doesn't seem to be quite as useful as it used to be. It doesn't take care of the user-file-permissions problem either (when moving the config file from user folder to shared folder).

===> In OfflineWorker.vbs, search *.mdb and replace it with *.db

===> The code for TweakMonkey.vbs

Code: Select all

'====================================================================================
' 
' MEDIAMONKEY SCRIPT: TweakMonkey v1.1 (last updated 2006-04-02)    by   The MediaMonkey Community
'  Initiated by Teknojnky on 2006-21-03 and open development for the whole MediaMonkey Community
'
'  TweakMonkey is a script used to tweak MediaMonkey, i.e. to make more advanced MediaMonkey settings
'   and changes available through MediaMonkey's options panels (See the integrated TweakMonkey options panes)
' 
'  Responsability for using this script (in all cases, in any way) is all on your own shoulders.
'
'====================================================================================

' Scripts that contain some of the functionality (but more powerful) of TweakMonkey:
' - StartupNode (Steegy)       http://www.mediamonkey.com/forum/viewtopic.php?t=7656
' - Backup script (Trixmoto)   http://www.mediamonkey.com/forum/viewtopic.php?t=7746

'***** You are free to do modify this code, but please detail any changes you make public 
'*****  and make sure you credit yourself (and previous authors).
'***** Changes/additions must be true to the spirit, i.e. don't include things that are better of in separate scripts.


' TODO -----------------------------------------------------
' Improve backup / restore functionality (autobackup each x days/startups)
' Equaliser auto on / auto of / don't touch (is this necessary ?)

    
Option Explicit


Const ScriptName = "TweakMonkey"     ' Script Name
Const Version = "1.1"                ' Version
Const LastUpdated = "2008-02-10"     ' Last updated

Const PlayNow = "Play in MediaMonkey"
Const PlayNext = "Play next in MediaMonkey"
Const PlayLast = "Play last in MediaMonkey"

Const LOCAL_APPLICATION_DATA = &H1c&
Dim AppDataPath : AppDataPath = CreateObject("Shell.Application").Namespace(LOCAL_APPLICATION_DATA).Self.Path & "\"

Dim Tree : Set Tree = SDB.MainTree
Dim INI : Set INI = SDB.IniFile
Dim UI : Set UI = SDB.UI 

Dim NodeRef : Set NodeRef = CreateObject("Scripting.Dictionary")
With NodeRef
    .Add "NowPlaying",     Tree.Node_NowPlaying
    .Add "Library",        Tree.Node_Library
        .Add "Location",       Tree.Node_Location
        .Add "Title",          Tree.PreviousSiblingNode(Tree.Node_Artist)
        .Add "Artist",         Tree.Node_Artist
        .Add "Album",          Tree.Node_Album
        .Add "Genre",          Tree.Node_Genre
        .Add "Year",           Tree.Node_Year
        .Add "Rating",         Tree.Node_Rating
        .Add "Classification", Tree.Node_Classification
        .Add "FilesToEdit",    Tree.Node_FilesToEdit
        .Add "VirtualCD",      Tree.Node_VirtualCD
        .Add "Previews",       Tree.Node_Previews
    .Add "Playlists",      Tree.Node_Playlists
    .Add "Search",         Tree.PreviousSiblingNode(Tree.Node_MyComputer)
    .Add "MyComputer",     Tree.Node_MyComputer
    .Add "NetRadio",       Tree.Node_Radio
    .Add "Web",            Tree.Node_Web
End With

Dim NodeCantExpand : Set NodeCantExpand = CreateObject("Scripting.Dictionary")
With NodeCantExpand            ' Set to True if a node can't be expanded (use False, or don't add an entry at all, if the node can be expanded)
    .Add "NowPlaying",     True
    .Add "Search",         True
End With

Dim NodeNoVisibility : Set NodeNoVisibility = CreateObject("Scripting.Dictionary")
With NodeNoVisibility          ' Set to True if node visibility can't be here (use False, or don't add an entry at all, if the node visibility can be changed)
    .Add "NowPlaying",     True
    .Add "Library",        True
        .Add "Location",       True
        .Add "Title",          True
        .Add "Artist",         True
        .Add "Album",          True
        .Add "Genre",          True
        .Add "Year",           True
        .Add "Rating",         True
        .Add "Classification", True
        .Add "FilesToEdit",    True
        .Add "VirtualCD",      True
        .Add "Previews",       True
    .Add "Playlists",      True
    .Add "Search",         True
    .Add "MyComputer",     True
    .Add "NetRadio",       True
    .Add "Web",            True
End With

Dim NodeNoLibraryChild : Set NodeNoLibraryChild = CreateObject("Scripting.Dictionary")
With NodeNoLibraryChild        ' Set to True if a subnode of Library node (use False, or don't add an entry at all, if the node isn't)
    .Add "NowPlaying",     True
    .Add "Library",        True
    .Add "Playlists",      True
    .Add "Search",         True
    .Add "MyComputer",     True
    .Add "NetRadio",       True
    .Add "Web",            True
End With

Const CTL_LINE_HEIGHT = 14

Dim WorkerArguments
Dim DEFAULT_BACKUP_DIR : DEFAULT_BACKUP_DIR = SDB.ApplicationPath & "Scripts\Auto\TweakMonkey\Backups\"
Dim ExtArray : ExtArray = Array("aac", "ape", "flac", "m4a", "m4b", "m4p", "mp3", "mp4", "mpc", "ogg", "shn", "wma", "wv")


' ******************************************************************************************************
' EVENT OnShutdown
' **********************************

Sub SDB_OnShutDown

    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
    
    SetINIString "PlaybackPosition", SDB.Player.PlayBackTime
    SetINIString "PlaybackState", SDB.Player.IsPlaying & "-" & SDB.Player.IsPaused


    If DoesPlaylistExist("NPSaved") Then SDB.PlaylistByTitle("NPSaved").Delete
    
    If SDB.Player.PlaylistCount > 0 Then
        If GetINIBool("UseFastNPLoading", False) Then
            SetINIString "NPCurrentSong", SDB.Player.CurrentSongIndex
            Dim RootPlaylist : Set RootPlaylist = SDB.PlaylistByTitle("")
            Dim NPSaved : Set NPSaved = RootPlaylist.CreateChildPlaylist("NPSaved")
            NPSaved.Clear
            
            Dim CSL : Set CSL = SDB.Player.CurrentSongList
            NPSaved.AddTracks CSL
            'Dim i
            'For i = 0 To CSL.Count - 1            ' NPSaved.AddTracks CSL    seems to be broken
            '    NPSaved.AddTrack(CSL.Item(i))
            'Next
        
            SDB.Player.PlaylistClear
        End If
    End If
    
    If GetINIBool("ClearNowPlayingOnExit", False) Then
        SDB.Player.PlaylistClear
    End If
        
    
    AddOfflineWorker "ClearSearchHistory", GetINIBool("Always_ClearSearchHistory", False)
    AddOfflineWorker "ClearPlaylistHistory", GetINIBool("Always_ClearPlaylistHistory", False)
    AddOfflineWorker "ClearURLHistory", GetINIBool("Always_ClearURLHistory", False)
    
    
    If WorkerArguments.Count > 0 Then
        Dim Key, ArgumentsList
        For Each Key In WorkerArguments.Keys
            If WorkerArguments(Key) = True Then
                ArgumentsList = ArgumentsList & " /" & Key
            End If
        Next
        If ArgumentsList <> "" Then
            Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
            WshShell.Run "wscript """ & SDB.ApplicationPath & "Scripts\Auto\TweakMonkey\OfflineWorker.vbs" & """" _
                        & " /INIPath:" & """" & GetINIPath & """" _
                        & " /DBPath:" & """" & GetDBPath & """" _
                        & " /APPPath:" & """" & SDB.ApplicationPath & """" _
                        & " /MyMusicPath:" & """" & AppDataPath & """" _
                        & ArgumentsList, 1, False
        End If
    End If

End Sub


' **********************************
' EVENT OnStartup
' **********************************

Sub OnStartup

    Set WorkerArguments = CreateObject("Scripting.Dictionary")
    Set SDB.Objects("WorkerArguments") = WorkerArguments

    Tree.Node_Library.Expanded = False
    
    'Do While Not SDB.IsRunning
    'Loop
    
    If GetINIBool("Always_Associate", False) Then
        AssociateOnStarup
    End If
    
    Script.RegisterEvent SDB, "OnShutDown", "SDB_OnShutDown"
    
    Dim TweakSheetRoot, TweakSheetTree, TweakSheetAutoExec, TweakSheetCleanReset, TweakSheetMMFiles, TweakSheetAssoc
    TweakSheetRoot = SDB.UI.AddOptionSheet("TweakMonkey & Script Options", Script.ScriptPath, "InitSheetRoot", "SaveSheetRoot", -1)
    TweakSheetAutoExec = SDB.UI.AddOptionSheet("AutoExec Options", Script.ScriptPath, "InitSheetAutoExec", "SaveSheetAutoExec", TweakSheetRoot)
    TweakSheetTree = SDB.UI.AddOptionSheet("Tree Node Options", Script.ScriptPath, "InitSheetTree", "SaveSheetTree", TweakSheetRoot)
    TweakSheetCleanReset = SDB.UI.AddOptionSheet("Clean/Reset Options", Script.ScriptPath, "InitSheetCleanReset", "SaveSheetCleanReset", TweakSheetRoot)
    TweakSheetMMFiles = SDB.UI.AddOptionSheet("MM Files + Backup Options", Script.ScriptPath, "InitSheetMMFiles", "SaveSheetMMFiles", TweakSheetRoot)
    TweakSheetAssoc = SDB.UI.AddOptionSheet("File Associations", Script.ScriptPath, "InitSheetAssoc", "SaveSheetAssoc", TweakSheetRoot)

    ' auto-set player volume at startup
    If GetINIBool("VolumeEnable", False) Then
        Dim Volume : Volume = CInt(GetINIString("Volume", "100"))
        SDB.Player.Volume = (Volume/100)
        SDB.ProcessMessages
    End If


    ' show/hide/expand/collapse any specific nodes ---------------------------------
    Dim NodeName
    For Each NodeName In NodeRef.Keys
        If CanNodeExpand(NodeName) Then
            If GetTreeExpanded(NodeName) Then
                If IsLibrarySubnode(NodeName) Then
                    NodeRef("Library").Expanded = True
                End If
                NodeRef(NodeName).Expanded = True
            End If
        End If
        If CanNodeVisibility(NodeName) Then 
            NodeRef(NodeName).Visible = GetTreeVisibility(NodeName) 
        End If
    Next


    ' startup node ----------------------------------------------------------------- 
    If GetINIBool("StartupNodeEnabled", False) Then
        Dim StartupNode : StartupNode = GetINIString("StartupNode", "") 
        If StartupNode <> "" Then
            If NodeRef.Exists(StartupNode) Then
                SDB.MainTree.CurrentNode = NodeRef(StartupNode)
                SDB.ProcessMessages
            End If
        End If
    End If

    
    If GetINIBool("UseFastNPLoading", False) Then
        If DoesPlaylistExist("NPSaved") Then
            If GetINIBool("AutoRandomize", False) Then
                RandomizePlayList SDB.PlaylistByTitle("NPSaved")
            End If
            SDB.Player.PlaylistClear    ' To make sure that the playlist is really empty
            SDB.Player.PlaylistAddTracks(SDB.PlaylistByTitle("NPSaved").Tracks)
            
            SDB.Player.CurrentSongIndex = CLng(GetINIString("NPCurrentSong", "0"))
            SDB.ProcessMessages
        End If
    Else
        If GetINIBool("LoadPlaylist", False) Then
            Dim PlaylistName : PlaylistName = GetINIString("Playlist", "")
            If PlaylistName <> "" Then
                If DoesPlaylistExist(PlaylistName) Then
                    SDB.Player.PlaylistClear
                    SDB.Player.PlaylistAddTracks(SDB.PlaylistByTitle(PlaylistName).Tracks)
                End If
            End If      
        End If
        If GetINIBool("AutoRandomize", False) Then
            RandomizeNowPlaying
        End If
    End If
    

    


    If GetINIString("AutoShuffle", "-") <> "-" Then
        If GetINIString("AutoShuffle", "-") = "on" Then
            SDB.Player.isShuffle = True
        Else
            SDB.Player.isShuffle = False
        End If
    End If 

    If GetINIString("AutoRepeat", "-") <> "-" Then 
        If GetINIString("AutoRepeat", "-") = "on" Then
            SDB.Player.isRepeat = True
        Else
            SDB.Player.isRepeat = False
        End If
    End If
    
    If GetINIString("AutoDJ", "-") <> "-" Then 
        If GetINIString("AutoDJ", "-") = "on" Then
            SDB.Player.isAutoDJ = True
        Else
            SDB.Player.isAutoDJ = False
        End If
    End If
    
    If (GetINIBool("AutoPlay", False) Or GetINIBool("AutoResume", False)) Then
        VolOrig = SDB.Player.Volume
        SDB.Player.Volume = 0
        
        If Not GetINIBool("LoadPlaylist", False) Then
            SDB.Player.Play
        End If
        If GetINIBool("AutoResume", False) And Not GetINIBool("LoadPlaylist", False) Then
            Dim PlayState : PlayState = Split(GetINIString("PlaybackState", "False-False"), "-")
            If PlayState(1) Then
                SDB.Player.Pause
            Else
                If PlayState(0) Then
                    SDB.Player.Play
                Else
                    SDB.Player.Stop
                End If
            End If
            If GetINIBool("AutoPlay", False) Then
                SDB.Player.Play
            End If
            Set TmrPB = SDB.CreateTimer(1500) 
            Script.RegisterEvent TmrPB, "OnTimer", "SetPlaybackTime" 
        Else
            If GetINIBool("AutoPlay", False) Then
                If SDB.Player.PlaylistCount > 0 Then
                    SDB.Player.CurrentSongIndex = 0
                End If
                SDB.Player.Play
            End If
            SDB.Player.Volume = VolOrig
        End If
        
    End If

End Sub

Dim TmrPB, VolOrig

Sub SetPlaybackTime(TmrPB)
    SDB.Player.PlayBackTime = CLng(GetINIString("PlaybackPosition", "0"))
    If Abs(SDB.Player.PlayBackTime - CLng(GetINIString("PlaybackPosition", "0"))) < 50 Then
        Script.UnregisterEvents(TmrPB)
        SDB.Player.Volume = VolOrig
    End If
End Sub


' ******************************************************************************************************
' INIT Sheet ROOT
' **********************************

Sub InitSheetRoot(Sheet)

    CreateLabel Sheet, String(20, Chr(171)) & "  T  W  E  A  K    T  H  E    M  O  N  K  E  Y  !!  " & String(19, Chr(187)), 10, 10, 400, 20
    CreateLabel Sheet, String(20, Chr(171)) & "  T  W  E  A  K    T  H  E    M  O  N  K  E  Y  !!  " & String(19, Chr(187)), 11, 10, 400, 20
    
    CreateLabel Sheet, "________________________________", 10, 41, 400, 20
    CreateLabel Sheet, "TweakMonkey Advanced Options Panel", 10, 40, 400, 20
    CreateLabel Sheet, "Last updated: " & LastUpdated & "             v" & Version _
        & vbNewLine _
        & vbNewLine & "Click a sub-tree to view/set the options." _
        & vbNewLine _
        & vbNewLine & "Most options will only take effect once MediaMonkey has been restarted." _
        & vbNewLine & "Some functions only execute when MediaMonkey is starting or shutting down.", 10, 55, 400, 20
        

End Sub


' **********************************
' SAVE Sheet ROOT
' **********************************

Sub SaveSheetRoot(Sheet)

End Sub 





' ******************************************************************************************************
' INIT Sheet AUTOEXEC
' **********************************

Sub InitSheetAutoExec(Sheet)

    Dim edt

    CreateLabel Sheet, "__________________________", 10, 11, 200, 20
    CreateLabel Sheet, "Turn features on/off at startup:", 10, 10, 200, 20

    CreateCheckBox Sheet, "Player Startup Volume", 10, 32, 140, 20, "VolumeEnable", "Enable/Disable the Startup Volume control", GetINIBool("VolumeEnable", False)

    ' Startup Volume control
    Set edt = UI.NewSpinEdit(Sheet) 
    edt.Common.ControlName = "Volume" 
    edt.Common.SetRect 145, 32, 45, 20 
    edt.MinValue = 0 
    edt.MaxValue = 100 
    edt.Common.Hint = "Set Volume at startup"
    
    Dim Volume : Volume = GetINIString("Volume", 100)
    edt.Value = Volume
  
    ' Auto-play/resume checkboxes  
    CreateCheckBox Sheet, "Auto Play", 10, 57, 80, 20, "AutoPlay", "Start Playing on startup", GetINIBool("AutoPlay", False)
    CreateCheckBox Sheet, "Resume State/Position", 100, 57, 130, 20, "AutoResume", "Resume song from last play time position", GetINIBool("AutoResume", False)

    ' Auto-Randomize Now Playing
    CreateCheckBox Sheet, "Randomize the playlist at startup", 245, 57, 200, 20, "AutoRandomize", "Randomize the selected playlist or 'Now Playing' at startup (not yet functional)", GetINIBool("AutoRandomize", False)

    CreateLabel Sheet, "Set Player:", 10, 85, 100, 20

    ' Player Auto-Shuffle'
    CreateLabel Sheet, "Shuffle", 75, 85, 70, 20
    CreateButton Sheet, GetINIString("AutoShuffle", "-"), 115, 82, 30, 20, "AutoShuffle", "ChangeChecEnabState"

    ' Player Auto-Repeat'
    CreateLabel Sheet, "Repeat", 75, 103, 70, 20
    CreateButton Sheet, GetINIString("AutoRepeat", "-"), 115, 102, 30, 20, "AutoRepeat", "ChangeChecEnabState"
    
    ' Player Auto-DJ'
    CreateLabel Sheet, "AutoDJ", 75, 123, 70, 20
    CreateButton Sheet, GetINIString("AutoDJ", "-"), 115, 122, 30, 20, "AutoDJ", "ChangeChecEnabState"

    ' Use Fast NowPlaying Loading
    Set edt = CreateCheckBox(Sheet, "Use Fast NowPlaying Loading", 10, 150, 180, 20, "UseFastNPLoading", "This will make MediaMonkey startup faster, with less disk usage", GetINIBool("UseFastNPLoading", False))
    Script.RegisterEvent edt.Common, "OnClick", "PlaylistToggleHandler"

    ' Auto-Play-Playlist
    Set edt = CreateCheckBox(Sheet, "Load alternate playlist at startup:", 10, 175, 200, 20, "LoadPlaylist", "Load this playlist at startup", GetINIBool("LoadPlaylist", False))
    Script.RegisterEvent edt.Common, "OnClick", "PlaylistToggleHandler"

    Dim Playlist : Playlist = GetINIString("Playlist", "")
    
    Set edt = UI.NewEdit(Sheet) 
    edt.Common.SetRect 200, 175, 255, 20 
    edt.Common.ControlName = "Playlist"
    edt.Text = Playlist
  
    'Set edt = UI.NewButton(Sheet) 
    'edt.Caption = "Choose Playlist"
    'edt.Common.SetRect 450, 130, 20, 20
    'edt.OnClickFunc = ""

    CreateLabel Sheet, "____________________________", 10, 216, 200, 20
    CreateLabel Sheet, "Turn features on/off at shutdown:", 10, 215, 200, 20
    
    ' Clear Now Playing On Exit
    CreateCheckBox Sheet, "Clear the Now Playing list on exit", 10, 235, 200, 20, "ClearNowPlayingOnExit", "This will clear the 'Now Playing' of tracks on exit", GetINIBool("ClearNowPlayingOnExit", False)

End Sub



Dim DontExecEvent : DontExecEvent = False


Sub PlaylistToggleHandler(CheckBox)
    If DontExecEvent Then Exit Sub
    
    Dim CState : CState = CheckBox.Checked
    DontExecEvent = True
    
    CheckBox.Common.TopParent.Common.ChildControl("LoadPlaylist").Checked = False
    CheckBox.Common.TopParent.Common.ChildControl("UseFastNPLoading").Checked = False
    
    CheckBox.Checked = CState
    
    DontExecEvent = False
End Sub


Sub ChangeChecEnabState(Button)
    If Button.Caption = "on" Then
        Button.Caption = "off"
    ElseIf Button.Caption = "off" Then
        Button.Caption="-"
    Else
        Button.Caption = "on"
        If Button.Common.ControlName = "AutoRepeat" Then Button.Common.TopParent.Common.ChildControl("AutoDJ").Caption = "off"
        If Button.Common.ControlName = "AutoDJ" Then Button.Common.TopParent.Common.ChildControl("AutoRepeat").Caption = "off"
    End If
End Sub


' **********************************
' SAVE Sheet AUTOEXEC
' **********************************

Sub SaveSheetAutoExec(Sheet)
    
    Dim LoadPlaylist, Playlist 

    ' Save volume
    SetINIString "Volume", Sheet.Common.ChildControl("Volume").Value
    SaveCheckValue Sheet, "VolumeEnable"
    
    ' Save auto-play/resume
    SaveCheckValue Sheet, "AutoPlay"
    SaveCheckValue Sheet, "AutoResume"

    ' Save LoadPlaylist and Playlist
    LoadPlaylist = Sheet.Common.ChildControl("LoadPlaylist").Checked 
    Playlist = Sheet.Common.ChildControl("Playlist").Text 
  
    If Playlist = "" Then 
        SetINIString "LoadPlaylist", "False"
    Else 
        SetINIString "LoadPlaylist", LoadPlaylist
    End If 
    
    SetINIString "Playlist", Playlist

    ' Save Auto-Randomize playlist
    SaveCheckValue Sheet, "AutoRandomize"
    SetINIString "AutoShuffle", Sheet.Common.ChildControl("AutoShuffle").Caption
    SetINIString "AutoRepeat", Sheet.Common.ChildControl("AutoRepeat").Caption
    SetINIString "AutoDJ", Sheet.Common.ChildControl("AutoDJ").Caption
    SaveCheckValue Sheet, "UseFastNPLoading"
    SaveCheckValue Sheet, "ClearNowPlayingOnExit"

End Sub 



' ******************************************************************************************************
' INIT Sheet TREE
' **********************************

Sub InitSheetTree(Sheet)

    Dim lbl, chk, edt, Tab
    
    CreateLabel Sheet, "_______________", 10, 11, 200, 20
    Set lbl = CreateLabel(Sheet, "Configure the tree:       (restart MM to take effect)", 10, 10, 80, 20)
    lbl.Autosize = True

    ' Startup Node 
    Set lbl = CreateLabel(Sheet, "Node to be selected at startup:", 10, 35, 100, 20)
    lbl.Autosize = True

    Set chk = CreateCheckBox(Sheet, " ", 170, 31, 16, 20, "StartupNodeEnabled", "Enable startup node", GetINIBool("StartupNodeEnabled", False))
    Script.RegisterEvent chk.Common, "OnClick", "StartupNodeEnabled_OnClick"

    Set edt = UI.NewDropdown(Sheet) 
    edt.Style = 2 
    edt.Common.ControlName = "StartupNode" 
    edt.Common.Left = 190 
    edt.Common.Top = 31  
    edt.Common.Hint = "MM will start with this node selected"
    edt.Common.Enabled = chk.Checked
  
    Dim StartupNode, Node, NodeIndex 
    StartupNode = GetINIString("StartupNode", "")
    NodeIndex = 0 
    
    Dim NodeName
    For Each NodeName In NodeRef.Keys
        If IsLibrarySubnode(NodeName) Then Tab = 4 Else Tab = 0
        edt.AddItem(Space(Tab) & NodeName) 
        If StartupNode = NodeName Then 
            edt.ItemIndex = NodeIndex 
        End If
        NodeIndex = NodeIndex + 1 
    Next 
    If StartupNode = "" Then 
        edt.ItemIndex = 1 
    End If 


    Dim Position : Position = 60
    Dim Visible, Expanded
    
    For Each NodeName In NodeRef.Keys 
    
        Visible = GetTreeVisibility(NodeName)
        Expanded = GetTreeExpanded(NodeName)
    
        If StartupNode = NodeName Then 
            Visible = True 
        End If 
        
        
        If IsLibrarySubnode(NodeName) Then Tab = 10 Else Tab = 0
        Set lbl = CreateLabel(Sheet, NodeName, 10 + Tab, Position, 80, 20)
        lbl.Autosize = True
        
        'If CanNodeVisibility(NodeName) Then
            Dim Ckb : Set Ckb = CreateCheckBox(Sheet, "Visible", 100, Position, 120, 20, NodeName & "Visible", "This will show/hide the " & NodeName & " Node", Visible)
            If Not CanNodeVisibility(NodeName) Then
                Ckb.Common.Enabled = False
                Ckb.Common.Hint = "This has to be set in MediaMonkey's own options."
                Ckb.Caption = "Visible¹"
            End If
        'End If
        
        If CanNodeExpand(NodeName) Then
            CreateCheckBox Sheet, "Expanded", 160, Position, 140, 20, NodeName & "Expanded", "This will expand/contract the " & NodeName & " Node", Expanded
        End If
    
        Position = Position + CTL_LINE_HEIGHT
    Next
    
    CreateLabel Sheet, "¹: This has to be set in MediaMonkey's own options.", 10, Position + 30, 200, 20
        
End Sub


Sub StartupNodeEnabled_OnClick(StartupNodeEnabled)

    Dim Sheet : Set Sheet = StartupNodeEnabled.Common.Parent
    Sheet.Common.ChildControl("StartupNode").Common.Enabled = StartupNodeEnabled.Checked

End Sub


' **********************************
' SAVE Sheet TREE
' **********************************

Sub SaveSheetTree(Sheet)

    Dim Node, Position, vis, Visible, Expanded, exp, lbl, StartupNode 

    ' Save startup node'
    Dim NodeNames : NodeNames = NodeRef.Keys
    StartupNode = NodeNames(Sheet.Common.ChildControl("StartupNode").ItemIndex)
    SetINIString "StartupNode", StartupNode
    SaveCheckValue Sheet, "StartupNodeEnabled"

    ' Save visible/expanded node options'
    Dim NodeName
    For Each NodeName in NodeRef.Keys 
        If CanNodeVisibility(NodeName) Then
            If Sheet.Common.ChildControl(NodeName & "Visible").Checked = True Then 
                SetTreeVisibility NodeName, True
            Else
                SetTreeVisibility NodeName, xIf(StartupNode = Node)
            End If
        End If
    
        If CanNodeExpand(NodeName) Then
            Expanded = Sheet.Common.ChildControl(NodeName & "Expanded").Checked 
            If StartupNode = NodeName Then 
                If IsLibrarySubnode(NodeName) Then 
                    SetTreeVisibility "Library", True
                    SetTreeExpanded "Library", True
                End If 
            End If
            SetTreeExpanded NodeName, Expanded
        End If
    Next 
    
End Sub 



' ******************************************************************************************************
' INIT Sheet CLEAN/RESET
' **********************************

Sub InitSheetCleanReset(Sheet)

    CreateLabel Sheet, "____________", 10, 11, 200, 20
    CreateLabel Sheet, "Clear histories:       (restart MM to take effect)", 10, 10, 80, 20
    
    CreateButton Sheet, "Clear Search History", 10, 35, 150, 20, "ClearSearchHistory", "ClearSearchHistory"
    CreateCheckBox Sheet, "Always automatically", 170, 35, 150, 20, "Always_ClearSearchHistory", "Always automaticly clear search history", GetINIBool("Always_ClearSearchHistory", False)
    
    CreateButton Sheet, "Clear Playlist History", 10, 60, 150, 20, "ClearPlaylistHistory", "ClearPlaylistHistory"
    CreateCheckBox Sheet, "Always automatically", 170, 60, 150, 20, "Always_ClearPlaylistHistory", "Always automaticly clear playlist history", GetINIBool("Always_ClearPlaylistHistory", False)
      
    CreateButton Sheet, "Clear Url History", 10, 85, 150, 20, "ClearURLHistory", "ClearURLHistory"
    CreateCheckBox Sheet, "Always automatically", 170, 85, 150, 20, "Always_ClearURLHistory", "Always automaticly clear url history", GetINIBool("Always_ClearURLHistory", False)
  
  
  
    CreateLabel Sheet, "________________________", 10, 131, 200, 20
    CreateLabel Sheet, "Reset user interface positions:       (restart MM to take effect)", 10, 130, 80, 20
    
    CreateButton Sheet, "Reset Player Position", 10, 155, 150, 20, "ResetPlayerPosition", "ResetPlayerPosition"
    
End Sub


Sub ResetPlayerPosition(Button)
    SetOfflineWorker "ResetPlayerPosition", True
End Sub

Sub ClearSearchHistory(Button)
    SetOfflineWorker "ClearSearchHistory", True
End Sub

Sub ClearPlaylistHistory(Button)
    SetOfflineWorker "ClearPlaylistHistory", True
End Sub

Sub ClearURLHistory(Button)
    SetOfflineWorker "ClearURLHistory", True
End Sub


' **********************************
' SAVE Sheet CLEAN/RESET
' **********************************

Sub SaveSheetCleanReset(Sheet)

    SaveCheckValue Sheet, "Always_ClearSearchHistory"
    SaveCheckValue Sheet, "Always_ClearPlaylistHistory"
    SaveCheckValue Sheet, "Always_ClearURLHistory"

End Sub 



' ******************************************************************************************************
' INIT Sheet MM FILES
' **********************************

Sub InitSheetMMFiles(Sheet)

    CreateLabel Sheet, "______________________________________", 10, 11, 200, 20
    CreateLabel Sheet, "Change location of the library and settings files:", 10, 10, 200, 20
    
    CreateLabel Sheet, "Location of the database:", 10, 35, 300, 20
    
    Dim edt : Set edt = UI.NewEdit(Sheet) 
    edt.Common.SetRect 10, 50, 445, 20 
    edt.Common.ControlName = "LocationOfDatabase"
    
    Dim DBName_previous : DBName_previous = GetDBPath
    SetINIString "DBName_previous", DBName_previous
    
    If GetOfflineWorker("ChangeLocationOfDatabase") Then
        edt.Text = GetINIString("DBName", DBName_previous)
    Else
        edt.Text = DBName_previous
    End If
    
    CreateCheckBox Sheet, "Move current database to the new location (won't overwrite)", 10, 75, 350, 20, "MoveDatabaseToNewLocation", "Move current database to the new location (won't overwrite)", GetOfflineWorker("MoveDatabaseToNewLocation")

    CreateCheckBox Sheet, "Keep copy of current database (copy instead of move)", 40, 95, 350, 20, "KeepCopyCurrentDatabase", "Keep copy of current database (copy instead of move)", GetOfflineWorker("KeepCopyCurrentDatabase")

    Dim INILocation : INILocation = GetINILocation
    Dim FolderDesc : FolderDesc = GetFolderDesc(INILocation)
    CreateLabel Sheet, "The configuration file (MediaMonkey.ini) is now located in " & FolderDesc & " folder.", 10, 128, 400, 20
    Dim FolderDesc2 : If INILocation = 2 Then FolderDesc2 = GetFolderDesc(1) Else FolderDesc2 = GetFolderDesc(2)
    CreateCheckBox Sheet, "Move it to " & FolderDesc2 & " folder", 10, 143, 250, 20, "MoveConfigFile", "Move the configuration file (MediaMonkey.ini)", GetOfflineWorker("MoveConfigFile")


    CreateLabel Sheet, "_____________________________", 10, 181, 200, 20
    CreateLabel Sheet, "Back up the library and settings files:", 10, 180, 200, 20

    CreateLabel Sheet, "Backup directory:", 10, 203, 100, 20
    
    Set edt = UI.NewEdit(Sheet) 
    edt.Common.SetRect 110, 200, 280, 20 
    edt.Common.ControlName = "BackupDirectory"
    edt.Text = GetINIString("BackupDirectory", DEFAULT_BACKUP_DIR)
    
    Script.RegisterEvent edt, "OnChange", "BackupDirectoryEdit_OnChange"
    
    CreateButton Sheet, "Browse...", 390, 200, 65, 20, "BrowseBackupDirectory", "BrowseBackupDirectory"
    
    CreateCheckBox Sheet, "Create backup (database + configuration files) on exit (only this time!!)", 10, 225, 400, 20, "CreateBackup", "Create backup (database + configuration files) on exit", GetOfflineWorker("CreateBackup")
    
    CreateCheckBox Sheet, "Restore backup (database + configuration files) on exit (only this time!!)", 10, 255, 400, 20, "RestoreBackup", "Restore backup (database + configuration files) on exit", GetOfflineWorker("RestoreBackup")
    CreateCheckBox Sheet, "Overwrite backup of last active database", 40, 275, 300, 20, "OverwriteRestoreBackup", "When a database backup is restored, the last active database (if present) will be moved as backup file." & vbNewLine & "Choose if you want to use (overwrite) this same backup file on each restore, or if you want to create a timestamped new one each time.", GetINIBool("OverwriteRestoreBackup", True)

    CreateLabel Sheet, "Zip file to recover:", 10, 298, 100, 20

    Set edt = UI.NewDropdown(Sheet)
    edt.Style = 2
    edt.Common.ControlName = "ZIPPathToRestore"
    edt.Common.SetRect 110, 295, 345, 20
    edt.Common.Hint = "Select the ZIP file (contains database + configuration files) that you want to restore"
    
    BackupDirectoryEdit_OnChange Sheet.Common.ChildControl("BackupDirectory")

End Sub

Function GetFolderDesc(INILocation)
    If INILocation = 1 Then
        GetFolderDesc = "your MediaMonkey Application Data"
    Else ' INILocation = 2
        GetFolderDesc = "the MediaMonkey program"
    End If
End Function

Dim DontTriggerTheEvent : DontTriggerTheEvent = False

Sub BackupDirectoryEdit_OnChange(Edit)

    If DontTriggerTheEvent Then Exit Sub

    Dim edt : Set edt = Edit.Common.TopParent.Common.ChildControl("ZIPPathToRestore")
    ClearDropDown edt
    
    If Edit.Text = "" Then Exit Sub

    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
    
    If Not FSO.FolderExists(Edit.Text) Then Exit Sub
    
    If Right(Edit.Text, 1) <> "\" Then
        DontTriggerTheEvent = True
        Edit.Text = Edit.Text & "\"
        DontTriggerTheEvent = False
    End If
    
    Dim Folder : Set Folder = FSO.GetFolder(Edit.Text)
    Dim fc : Set fc = Folder.Files
    Dim icnt : icnt = 0
    Dim f1 : For Each f1 in fc
        icnt = icnt + 1
        edt.AddItem f1.Name
        If GetINIString("ZIPPathToRestore", "") = f1.Path Then edt.ItemIndex = icnt - 1
    Next
    
End Sub


Sub BrowseBackupDirectory(Button)

    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
    If Not FSO.FolderExists(DEFAULT_BACKUP_DIR) Then
        FSO.CreateFolder DEFAULT_BACKUP_DIR
    End If
    
    Dim Ret : Ret = SDB.SelectFolder(Button.Common.TopParent.Common.ChildControl("BackupDirectory").Text, "Select folder for backups")
    If Ret <> "" Then
        Button.Common.TopParent.Common.ChildControl("BackupDirectory").Text = Ret
    End If

End Sub


' **********************************
' SAVE Sheet MM FILES
' **********************************

Sub SaveSheetMMFiles(Sheet)

    Sheet.Common.ChildControl("LocationOfDatabase").Text = Trim(Sheet.Common.ChildControl("LocationOfDatabase").Text)
    If Sheet.Common.ChildControl("LocationOfDatabase").Text <> GetINIString("DBName_previous", "") Then
        If Right(Sheet.Common.ChildControl("LocationOfDatabase").Text, 4) = ".db" Then
            SetINIString "DBName", Sheet.Common.ChildControl("LocationOfDatabase").Text
            SetOfflineWorker "ChangeLocationOfDatabase", True
            SetOfflineWorker "MoveDatabaseToNewLocation", Sheet.Common.ChildControl("MoveDatabaseToNewLocation").Checked
            SetOfflineWorker "KeepCopyCurrentDatabase", Sheet.Common.ChildControl("KeepCopyCurrentDatabase").Checked
        Else
            SDB.MessageBox "Database file must have file extension *.db!" & vbNewLine &"Also make sure that the path doesn't contain quotation marks." & vbNewLine & vbNewLine & "The database location will not be changed.", mtError, Array(mbOk)
        End If
    End If
    
    SetOfflineWorker "MoveConfigFile", Sheet.Common.ChildControl("MoveConfigFile").Checked
    
    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
    If FSO.FolderExists(Sheet.Common.ChildControl("BackupDirectory").Text) Then
        SetINIString "BackupDirectory", Sheet.Common.ChildControl("BackupDirectory").Text
    End If
    
    SetOfflineWorker "CreateBackup", Sheet.Common.ChildControl("CreateBackup").Checked
    
    If Sheet.Common.ChildControl("ZIPPathToRestore").Text <> "" Then
        SetOfflineWorker "RestoreBackup", Sheet.Common.ChildControl("RestoreBackup").Checked
        SetINIString "ZIPPathToRestore", Sheet.Common.ChildControl("BackupDirectory").Text & Sheet.Common.ChildControl("ZIPPathToRestore").Text
    Else
        SetOfflineWorker "RestoreBackup", False
    End If
    SaveCheckValue Sheet, "OverwriteRestoreBackup"
    
End Sub 



' ******************************************************************************************************
' INIT Sheet ASSOC
' **********************************

Sub InitSheetAssoc(Sheet)

    CreateLabel Sheet, "____________________________________", 10, 11, 200, 20
    CreateLabel Sheet, "Associate MediaMonkey with music file types:", 10, 10, 200, 20
    
    CreateLabel Sheet, "!! First make sure that MediaMonkey doesn't automaticly make file associations on startup !!", 10, 35, 400, 20
    CreateLabel Sheet, " -> uncheck ""General"" > ""File Types"" > ""Repair file associations on startup (recommended)""", 10, 50, 400, 20
    
    
    Dim Ext, YPos0, YPos, XPos, chk, lbl, notText
    YPos0 = 70
    YPos = 0
    XPos = 20
    For Each Ext In ExtArray
        Set chk = CreateCheckBox(Sheet, Ext, XPos, YPos0 + YPos, 50, 20, Ext & "FileExt", "Check to associate MM with " & Ext & "-files", GetINIBool(Ext & "FileExt", False))
        Script.RegisterEvent chk.Common, "OnClick", "FileExt_OnClick"
        If Not IsMMAssociated(Ext) Then
            notText = " NOT"
        Else
            notText = ""
        End If
        Set lbl = CreateLabel(Sheet, "currently" & notText & " associated", XPos + 50, YPos0 + YPos + 3, 20, 20)
        lbl.Common.ControlName = Ext & "Label"
        
        YPos = YPos + 17
        If YPos >= 150 Then
            YPos = 0
            XPos = 250
        End If
    Next
    
    Dim WB : Set WB = UI.NewActiveX(Sheet, "Shell.Explorer")
    WB.Common.SetRect 260, 240, 50, 50
    If WB.Interf.Document Is Nothing Then
        WB.Interf.Navigate "about:"
    End If
    WB.Interf.Document.Write("<html><body style=""margin: 0"" scroll=""no""></body></html>")
    WB.Common.ControlName = "WBIconPreview"

    CreateButton Sheet, "Apply Associations Now", 17, 240, 150, 20, "AssociateNow", "AssociateNow"
    CreateCheckBox Sheet, "Automatically associate on MM startup", 20, 270, 210, 20, "Always_Associate", "Always automaticly associate these file types on startup", GetINIBool("Always_Associate", False)
    
End Sub


Sub FileExt_OnClick(CheckBox)
    Dim Ext : Ext = CheckBox.Caption
    Dim IconFolder : IconFolder = SDB.ApplicationPath & "Scripts\Auto\TweakMonkey\Icons\"
    If CheckBox.Common.TopParent.Common.ChildControl("WBIconPreview").Interf.Document Is Nothing Then
        CheckBox.Common.TopParent.Common.ChildControl("WBIconPreview").Interf.Navigate "about:"
    End If
    Dim Doc : Set Doc = CheckBox.Common.TopParent.Common.ChildControl("WBIconPreview").Interf.Document
    Doc.Write("<html><body style=""margin: 0"" scroll=""no""><img src=""" & IconFolder & Ext & ".ico" & """ height=""48"" width=""48""></body></html>")
    Doc.Close
End Sub


' **********************************
' SAVE Sheet ASSOC
' **********************************

Sub SaveSheetAssoc(Sheet)

    Dim Ext
    For Each Ext In ExtArray
        SaveCheckValue Sheet, Ext & "FileExt"
    Next
    
    SaveCheckValue Sheet, "Always_Associate"
    
End Sub


Sub AssociateWithMM(Ext)
    Dim IconFolder : IconFolder = SDB.ApplicationPath & "Scripts\Auto\TweakMonkey\Icons\"
    Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
    WshShell.RegWrite "HKEY_CLASSES_ROOT\." & Ext & "\", Ext & "file"
    WshShell.RegWrite "HKEY_CLASSES_ROOT\" & Ext & "file\DefaultIcon\", Esc(IconFolder & Ext & ".ico")
    WshShell.RegWrite "HKEY_CLASSES_ROOT\" & Ext & "file\shell\Play\", PlayNow
    WshShell.RegWrite "HKEY_CLASSES_ROOT\" & Ext & "file\shell\Play\command\", QStr(Esc(SDB.ApplicationPath & "MediaMonkey.exe")) & " ""%1"""
    WshShell.RegWrite "HKEY_CLASSES_ROOT\" & Ext & "file\shell\PlayNext\", PlayNext
    WshShell.RegWrite "HKEY_CLASSES_ROOT\" & Ext & "file\shell\PlayNext\command\", QStr(Esc(SDB.ApplicationPath & "MediaMonkey.exe")) & " /NEXT ""%1"""
    WshShell.RegWrite "HKEY_CLASSES_ROOT\" & Ext & "file\shell\PlayLast\", PlayLast
    WshShell.RegWrite "HKEY_CLASSES_ROOT\" & Ext & "file\shell\PlayLast\command\", QStr(Esc(SDB.ApplicationPath & "MediaMonkey.exe")) & " /ADD ""%1"""
End Sub

Sub DissociateWithMM(Ext)
    Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
    RegDeleteSafe "HKEY_CLASSES_ROOT\." & Ext & "\"
End Sub

Sub AssociateOnStarup
    Dim Ext
    For Each Ext In ExtArray
        If GetINIBool(Ext & "FileExt", False) Then
            AssociateWithMM(Ext)
        End If
    Next
    RebuildIconCache
End Sub

Sub AssociateNow(Button)
    Dim Ext, notText
    For Each Ext In ExtArray
        If Button.Common.TopParent.Common.ChildControl(Ext & "FileExt").Checked Then
            AssociateWithMM(Ext)
            notText = ""
        Else
            DissociateWithMM(Ext)
            notText = " NOT"
        End If
        Button.Common.TopParent.Common.ChildControl(Ext & "Label").Caption = "currently" & notText & " associated"
    Next
    RebuildIconCache
End Sub

Function IsMMAssociated(Ext)
    IsMMAssociated = False
    
    Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
    
    If RegReadSafe("HKEY_CLASSES_ROOT\." & Ext & "\") = Ext & "file" Then
        If InStr(RegReadSafe("HKEY_CLASSES_ROOT\" & Ext & "file\shell\Play\command\"), "MediaMonkey") Then
            If InStr(RegReadSafe("HKEY_CLASSES_ROOT\" & Ext & "file\shell\PlayNext\command\"), "MediaMonkey") Then
                If InStr(RegReadSafe("HKEY_CLASSES_ROOT\" & Ext & "file\shell\PlayLast\command\"), "MediaMonkey") Then
                    IsMMAssociated = True
                End If
            End If
        End If
    End If
End Function

Sub RebuildIconCache
    'Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
    'Dim LocAppData : LocAppData = RegReadSafe("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Local AppData")

    'Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
    'If FSO.FileExists(LocAppData & "IconCache.db") Then FSO.DeleteFile LocAppData & "IconCache.db", True
    
    ' A POSTMESSAGE IS NECESSARY (BUT NOT POSSIBLE WITHING VBSCRIPT)
End Sub

' ******************************************************************************************************
' HELPER METHODS
' **********************************

Function DoesPlaylistExist(PlaylistName)
    DoesPlaylistExist = (SDB.PlaylistByTitle(PlaylistName).Id <> 0)
End Function

Sub RandomizePlayList(Playlist)
    Randomize
    Dim Songlist : Set Songlist = Playlist.Tracks
    Dim n : n = SongList.Count
    
    Dim i
    For i = 0 To n - 1
        Playlist.MoveTrack Songlist.Item(i), Songlist.Item(Int(n * Rnd))
    Next
End Sub

Sub RandomizeNowPlaying        
    Randomize
    Dim n : n = SDB.Player.PlaylistCount
    
    Dim i
    For i = 0 To n - 1
        SDB.Player.PlaylistMoveTrack i, Int(n * Rnd)
    Next
End Sub


'%%%%%%%%%%%%%%%
' INI PROPS
'%%%%%%%%%%%%%%%

Function GetINIBool(pName, pValueIfMissing)
    If pValueIfMissing Then
        If SDB.IniFile.StringValue(ScriptName, pName) = "False" Then
            GetINIBool = False
        Else
            GetINIBool = True
        End If
    Else
        If SDB.IniFile.StringValue(ScriptName, pName) = "True" Then
            GetINIBool = True
        Else
            GetINIBool = False
        End If
    End If
End Function

Function GetINIString(pName, pValueIfMissing)
    GetINIString = SDB.IniFile.StringValue(ScriptName, pName)
    If GetINIString = "" Then
        GetINIString = pValueIfMissing
	End If
End Function

Sub SetINIString(pName, pValue)
	SDB.IniFile.StringValue(ScriptName, pName) = pValue
End Sub

Sub SaveCheckValue(Sheet, CheckName)
    SetINIString CheckName, Sheet.Common.ChildControl(CheckName).Checked
End Sub
Sub SaveTextValue(Sheet, CheckName)
    SetINIString CheckName, Sheet.Common.ChildControl(CheckName).Text
End Sub


'%%%%%%%%%%%%%%%
' TREE PROPS
'%%%%%%%%%%%%%%%

Function GetTreeVisibility(NodeName)
    If INI.StringValue("Tree", NodeName) = "0" Then
        GetTreeVisibility = False
    Else
        GetTreeVisibility = True
    End If
End Function

Function SetTreeVisibility(NodeName, Visible)
    If Visible Then
        INI.StringValue("Tree", NodeName) = "1"
    Else
        INI.StringValue("Tree", NodeName) = "0"
    End If
End Function

Function GetTreeExpanded(NodeName)
    GetTreeExpanded = GetINIBool(NodeName & "_Expanded", False)
End Function

Function SetTreeExpanded(NodeName, Expanded)
    SDB.IniFile.StringValue(ScriptName, NodeName & "_Expanded") = Expanded
End Function


'%%%%%%%%%%%%%%%
' TREE METHODS
'%%%%%%%%%%%%%%%

Function CanNodeExpand(NodeName)
    CanNodeExpand = True
    If NodeCantExpand.Exists(NodeName) Then
        If NodeCantExpand(NodeName) Then
            CanNodeExpand = False
        End If
    End If
End Function

Function CanNodeVisibility(NodeName)
    CanNodeVisibility = True
    If NodeNoVisibility.Exists(NodeName) Then
        If NodeNoVisibility(NodeName) Then
            CanNodeVisibility = False
        End If
    End If
End Function

Function IsLibrarySubnode(NodeName)
    IsLibrarySubnode = True
    If NodeNoLibraryChild.Exists(NodeName) Then
        If NodeNoLibraryChild(NodeName) Then
            IsLibrarySubnode = False
        End If
    End If
End Function


'%%%%%%%%%%%%%%%
' UTILITY
'%%%%%%%%%%%%%%%

Function xIf(Condition)
    xIf = Condition
End Function

Function Esc(InString)
    Esc = Replace(InString, "\", "\\")
End Function

Function QStr(InString)
    QStr = """" & InString & """"
End Function


'%%%%%%%%%%%%%%%
' REGISTRY
'%%%%%%%%%%%%%%%

Function RegReadSafe(Path)
    On Error Resume Next
    Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
    RegReadSafe = WshShell.RegRead(Path)
    On Error Goto 0
End Function

Sub RegDeleteSafe(Path)
    On Error Resume Next
    Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
    WshShell.RegDelete Path
    On Error Goto 0
End Sub


'%%%%%%%%%%%%%%%
' FORM CREATION
'%%%%%%%%%%%%%%%

Function CreateCheckBox(pOwner, pCaption, pX, pY, pWidth, pHeight, pControlName, pHint, pChecked)
    Set CreateCheckBox = SDB.UI.NewCheckBox(pOwner)
    CreateCheckBox.Caption = pCaption
    CreateCheckBox.Common.SetRect pX, pY, pWidth, pHeight
    CreateCheckBox.Common.ControlName = pControlName
    CreateCheckBox.Common.Hint = pHint
    CreateCheckBox.Checked = pChecked
End Function

Function CreateButton(pOwner, pCaption, pX, pY, pWidth, pHeight, pControlName, pOnClickHandler)
    Set CreateButton = SDB.UI.NewButton(pOwner)
    CreateButton.Caption = pCaption
    CreateButton.Common.SetRect pX, pY, pWidth, pHeight
    CreateButton.Common.ControlName = pControlName
    If pOnClickHandler <> "" Then
        Script.RegisterEvent CreateButton.Common, "OnClick", pOnClickHandler
    End If
End Function

Function CreateLabel(pOwner, pCaption, pX, pY, pWidth, pHeight)
    Set CreateLabel = SDB.UI.NewLabel(pOwner)
    CreateLabel.Common.SetRect pX, pY, pWidth, pHeight 
    CreateLabel.Caption = pCaption
End Function

Sub ClearDropDown(DropDown)
  Dim i : For i = DropDown.ItemCount - 1 To 0 Step -1
    DropDown.DeleteItem i
  Next
  DropDown.Text = ""
End Sub


'%%%%%%%%%%%%%%%
' OFFLINE WORKER
'%%%%%%%%%%%%%%%

Sub SetOfflineWorker(Key, State)
    Dim WorkerArguments : Set WorkerArguments = SDB.Objects("WorkerArguments")
    If WorkerArguments.Exists(Key) Then
        WorkerArguments(Key) = State
    Else
        WorkerArguments.Add Key, State
    End If
End Sub

Sub AddOfflineWorker(Key, State)
    If Not GetOfflineWorker(Key) Then
        SetOfflineWorker Key, State
    End If
End Sub

Function GetOfflineWorker(Key)
    Dim WorkerArguments : Set WorkerArguments = SDB.Objects("WorkerArguments")
    If WorkerArguments.Exists(Key) Then
        GetOfflineWorker = WorkerArguments(Key)
    Else
        GetOfflineWorker = False
    End If
End Function


'%%%%%%%%%%%%%%%
' MEDIAMONKEY
'%%%%%%%%%%%%%%%

Function GetINIPath()
    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject") 
  
    GetINIPath = AppDataPath & "MediaMonkey\MediaMonkey.ini"
    If FSO.FileExists(GetINIPath) Then Exit Function
  
    GetINIPath = SDB.ApplicationPath & "MediaMonkey.ini"
    If FSO.FileExists(GetINIPath) Then Exit Function
   
    GetINIPath = ""
End Function

Function GetINILocation()
    Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject") 
  
    If FSO.FileExists(AppDataPath & "MediaMonkey\MediaMonkey.ini") Then
        GetINILocation = 1
    ElseIf FSO.FileExists(SDB.ApplicationPath & "MediaMonkey.ini") Then
        GetINILocation = 2
    Else   
        GetINILocation = 0
    End If
End Function

Function GetDBPath()
    GetDBPath = SDB.Database.Path
End Function
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
ninjapanda
Posts: 4
Joined: Wed Dec 13, 2006 3:18 am

Post by ninjapanda »

Hey, I'm having some problems with this script.

Upon installation of this script the built in media hotkeys to my HP pavilion become incompatible with MM3. Uninstalling the script left me without the advantages of tweakmonkey as well as having no media keys. I was forced to do a system restore after use of a Winamp plugin did not fully resolve the issue either.

Is there a way I can get Tweakmonkey to work and keep my precious built in media hotkeys?

- Thanks for any help

p.s. I am also getting the access violations that ppl are already aware of.
the.jowetts
Posts: 2
Joined: Sun May 25, 2008 6:57 pm

Auto execute or on shutdown

Post by the.jowetts »

Dear Steegy,

I think you have the answer to my problem (well one of them anyway).
Sorry if this is off-topic, but I'm old and can't learn new tricks.
I need the "Export all playlists" script to execute upon exiting MM so my MM playlists work in my Network player.
You appear to have done this for some functions in TweakMonkey. I'm not asking for it to be added to TweakMonkey (although that would be nice), I just need a chunk of text to add to ExportM3Us.vbs or Export M3Us_modified.vbs and instructions on how to do it.
Post Reply