Undo Auto Organise 1.0 [MM2]

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

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

Undo Auto Organise 1.0 [MM2]

Post by trixmoto » Thu May 17, 2007 6:41 am

This is a new script which remembers all the files that were moved during the last auto-organise. It adds a button on the standard toolbar which can be used to move all of these files back again.

I have not tested this script on MM3 and am unsure how it will work with the new auto-auto-organise functionality, but if someone wants to let me know that would be good!

Anyway, the installer can be download from my website. let me know what you think. :)
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.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

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

Post 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
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.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE

Post Reply