by trixmoto » Thu May 17, 2007 6:42 am
Code: Select all
'
' MediaMonkey Script
'
' NAME: UndoAutoOrganise 1.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 17/05/2007
'
' INSTALL: Copy to Scripts\Auto directory
'
Option Explicit
Sub OnStartUp
'create button
Dim btn : Set btn = SDB.UI.AddMenuItem(SDB.UI.Menu_TbStandard,0,0)
btn.Caption = "UndoAutoOrganise"
btn.IconIndex = 6
btn.Enabled = False
Set SDB.Objects("UndoAutoOrganiseButt") = btn
'register events
Script.RegisterEvent btn, "OnClick", "Undo"
Script.RegisterEvent SDB, "OnBeforeTracksMove", "Record"
End Sub
Sub Record(tracks,paths,move)
'check move
If Not (move) Then
Exit Sub
End If
'store changes
Dim i : i = 0
Dim dic : Set dic = CreateObject("Scripting.Dictionary")
For i = 0 To tracks.Count-1
Call dic.Add(tracks.Item(i),paths.Item(i)&"|"&tracks.Item(i).Path)
Next
Set SDB.Objects("UndoAutoOrganiseDict") = dic
'enable button
Dim btn : Set btn = SDB.Objects("UndoAutoOrganiseButt")
If Not (btn Is Nothing) Then
btn.Enabled = True
End If
End Sub
Sub Undo(but)
'get changes
Dim dic : Set dic = SDB.Objects("UndoAutoOrganiseDict")
If dic Is Nothing Then
Exit Sub
End If
'confirm
Select Case SDB.MessageBox("UndoAutoOrganise: Are you sure you wish to undo "&dic.Count&" file organisations?",mtConfirmation,Array(mbYes,mbNo))
Case mrYes
'continue
Case Else
Exit Sub
End Select
'initialise
Dim i : i = 0
Dim j : j = 0
Dim a : a = dic.Keys
Dim f : Set f = CreateObject("Scripting.FileSystemObject")
Dim l : Set l = SDB.NewSongList
'undo moves
For i = 0 To UBound(a)
Dim b : b = Split(dic.Item(a(i)),"|")
If f.FileExists(b(0)) Then
j = j + 1
a(i).Path = b(1)
Call l.Add(a(i))
End If
Next
Call l.UpdateAll()
'disable button
Dim btn : Set btn = SDB.Objects("UndoAutoOrganiseButt")
If Not (btn Is Nothing) Then
btn.Enabled = False
End If
'summary
Set SDB.Objects("UndoAutoOrganiseDict") = Nothing
Dim s : s = "All"
If Not (j = dic.Count) Then
s = j&" of "&dic.Count
End If
Call SDB.MessageBox("UndoAutoOrganise: "&s&" file organisations have been successfully undone.",mtInformation,Array(mbOk))
End Sub
[code]'
' MediaMonkey Script
'
' NAME: UndoAutoOrganise 1.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 17/05/2007
'
' INSTALL: Copy to Scripts\Auto directory
'
Option Explicit
Sub OnStartUp
'create button
Dim btn : Set btn = SDB.UI.AddMenuItem(SDB.UI.Menu_TbStandard,0,0)
btn.Caption = "UndoAutoOrganise"
btn.IconIndex = 6
btn.Enabled = False
Set SDB.Objects("UndoAutoOrganiseButt") = btn
'register events
Script.RegisterEvent btn, "OnClick", "Undo"
Script.RegisterEvent SDB, "OnBeforeTracksMove", "Record"
End Sub
Sub Record(tracks,paths,move)
'check move
If Not (move) Then
Exit Sub
End If
'store changes
Dim i : i = 0
Dim dic : Set dic = CreateObject("Scripting.Dictionary")
For i = 0 To tracks.Count-1
Call dic.Add(tracks.Item(i),paths.Item(i)&"|"&tracks.Item(i).Path)
Next
Set SDB.Objects("UndoAutoOrganiseDict") = dic
'enable button
Dim btn : Set btn = SDB.Objects("UndoAutoOrganiseButt")
If Not (btn Is Nothing) Then
btn.Enabled = True
End If
End Sub
Sub Undo(but)
'get changes
Dim dic : Set dic = SDB.Objects("UndoAutoOrganiseDict")
If dic Is Nothing Then
Exit Sub
End If
'confirm
Select Case SDB.MessageBox("UndoAutoOrganise: Are you sure you wish to undo "&dic.Count&" file organisations?",mtConfirmation,Array(mbYes,mbNo))
Case mrYes
'continue
Case Else
Exit Sub
End Select
'initialise
Dim i : i = 0
Dim j : j = 0
Dim a : a = dic.Keys
Dim f : Set f = CreateObject("Scripting.FileSystemObject")
Dim l : Set l = SDB.NewSongList
'undo moves
For i = 0 To UBound(a)
Dim b : b = Split(dic.Item(a(i)),"|")
If f.FileExists(b(0)) Then
j = j + 1
a(i).Path = b(1)
Call l.Add(a(i))
End If
Next
Call l.UpdateAll()
'disable button
Dim btn : Set btn = SDB.Objects("UndoAutoOrganiseButt")
If Not (btn Is Nothing) Then
btn.Enabled = False
End If
'summary
Set SDB.Objects("UndoAutoOrganiseDict") = Nothing
Dim s : s = "All"
If Not (j = dic.Count) Then
s = j&" of "&dic.Count
End If
Call SDB.MessageBox("UndoAutoOrganise: "&s&" file organisations have been successfully undone.",mtInformation,Array(mbOk))
End Sub[/code]