Page 1 of 2

Script Helper Methods

Posted: Mon Jan 30, 2006 8:38 pm
by Steegy
Shared Helper Scripts (with subs, functions and constants):

These helper method utility files will be required in almost all of my future scripts.
They have the intention of sharing commonly used methods between scripts.

This "concept" is experimental! The utility files will get updated and can change. Please take this into account.

http://home.tiscali.be/ruben.castelein/ ... ntrols.vbs
http://home.tiscali.be/ruben.castelein/ ... eneral.vbs
http://home.tiscali.be/ruben.castelein/ ... ty_SQL.vbs

Utility Controls mirror
Utility General mirror

These files have to be put in MediaMonkey's Scripts folder.

If you have useful methods (subs and functions) for "General", "Controls", "SQL", ... please share them so I can add them. I'm still adding them myself.
The intention is to bundle nicely written pieces of code, with appropriate explanation, and "release dates" for these files, in the future.

They can be a great way of easily adding new functionality to MediaMonkey (e.g. writing/reading ID3 frames)

Cheers
Steegy

Posted: Tue Jan 31, 2006 5:32 am
by trixmoto
This is a nice idea.

Can I suggest an improvment for your "GetINIPath" function though:

Code: Select all

Function getinipath()
  Dim ini1,ini2,found,path1,path2
  found = 0
  getinipath = ""
  
  path2 = SDB.MyMusicPath&"MediaMonkey\MediaMonkey.ini"
  If fso.FileExists(path2) Then
    found = 2
    Set ini2 = fso.GetFile(path2)
  End If  
  
  path1 = SDB.ApplicationPath&"MediaMonkey.ini"
  If fso.FileExists(path1) Then
    found = found + 1
    Set ini1 = fso.GetFile(path1)
  End If
  
  Select Case found
    case 1  'found only ini 1
      getinipath = path1
    case 2  'found only ini 2
      getinipath = path2
    case 3  'found both so use largest
      If ini1.Size > ini2.Size Then
        getinipath = path1
      Else
        getinipath = path2
      End If
   End Select

   Set ini1 = Nothing
   Set ini2 = Nothing
End Function

Posted: Tue Jan 31, 2006 5:48 am
by Steegy
Thank You.

But please, can you explain to me:
I thought MediaMonkey always uses the "MediaMonkey.ini" file in directory "My Documents\My Music\MediaMonkey\" (or similar) ?
If it doesn't exist, it is automaticly created.
Isn't the program folder ini just used for some winamp script compatibility?
I'm confused now... :-?

Cheers
Steegy

Posted: Tue Jan 31, 2006 6:09 am
by psyXonova
This answers your question...
http://www.mediamonkey.com/forum/viewtopic.php?t=7766

I have one though. How can i call those functions from another vbs file?

Posted: Tue Jan 31, 2006 6:48 am
by mockturtle
The new release will include new function:

Code: Select all

Script.Include "script name.vbs"
and so usage of these scripts will be easier. Note though, that doing so increases start-up time of your script slightly and so if you need only one function from another file, it might be better to copy that function to your script and save scripting engine parsing of whole included script file.

Jiri

Posted: Tue Jan 31, 2006 7:06 am
by psyXonova
Cool, thanks Jiri...
Thats a nice addition, but as you said must be used with considerations

Posted: Tue Jan 31, 2006 8:11 am
by trixmoto
Yes, I moved the .ini file from my music folder and added the DBName entry so that I could keep all my music (and the MM app) on my external harddrive, meaning I can use it at work without needing to copy any files onto my work machine.

Posted: Tue Jan 31, 2006 9:07 am
by Steegy
@psyxonova
See a new script SwitchFields http://www.mediamonkey.com/forum/viewtopic.php?t=7920 where I use this. (see imports section + it uses one function written at the end of the file)
This is only a "preview" what means that I wanted to share the idea and invite all scripters to add (and improve) functionality of these helper scripts. I suppose we'd better wait with using this concept extensively, until these helper files are "approved" and contain more useful things.
I think it would be the best if we all use the same helper scripts (e.g. "Utility_General.vbs" and "Utility_SQL.vbs", ...) instead of all having us own (e.g. "HelperScript_Psyxonova.vbs", "TrixmotoHelpers.vbs", "SteegyUtility.vbs", ...) what would cause a lot of problems, instead of making things better, imho.

@jiri
I suppose this Script.Include method does the same thing of what I am doing in my SwitchFields script?
Actually, I had something in my mind so you could let MediaMonkey make references to helper methods.
E.g. if helper script "Utility_General.vbs" contains a function GetIniFile(), then you could use something like
Script.Use "Utility_General.vbs", "GetIniFile"
Then, everytime GetIniFile is used in the program, it would executed the referenced code in the "Utility_General.vbs" file. (instead of including the whole script file as it is now). That would work much faster.
It might even be better if we could use "Gen.GetIniFile" (where "Gen" indicated a class) so there would be less problems with
naming collisions and methods would be easier to recognise. (e.g. SQL.OpenDatabaseConnection("MyDB.mdb") )
Any way, with referenced scripts, it should also be possible for one referenced method to use another (not referenced) method in the same helper file.

This is probably much too difficult to create, but it would be very cool and would make helper scripts useful without extra overhead.

Anyway, thank you very much for responding so fast and to implement this first method! You really are helping scripting for MM a lot (with this, with added menu references, new events, ...) :D

Cheers
Steegy

Posted: Tue Jan 31, 2006 9:46 am
by Steegy
@Trixmoto and other scripters

Is this better?

Code: Select all

' Returns the path to MediaMonkey's configuration (ini) file or "" if it doesn't exist
Function GetINIPath()

  GetINIPath = ""
  Dim FoundININumber, INIPath_MyMusic, INIPath_Program, FSO

  FoundININumber = 0
  INIPath_MyMusic = SDB.MyMusicPath & "MediaMonkey\MediaMonkey.ini"
  INIPath_Program = SDB.ApplicationPath & "MediaMonkey.ini"
  Set FSO = CreateObject("Scripting.FileSystemObject")

  If FSO.FileExists(INIPath_MyMusic) Then FoundININumber = FoundININumber + 1
  If FSO.FileExists(INIPath_Program) Then FoundININumber = FoundININumber + 2

  Select Case FoundININumber
    Case 1:
      GetINIPath = INIPath_MyMusic
    Case 2:
      GetINIPath = INIPath_Program
    Case 3:
      If FSO.GetFile(INIPath_MyMusic).Size > FSO.GetFile(INIPath_Program).Size Then 
        GetINIPath = INIPath_MyMusic
      Else 
        GetINIPath = INIPath_Program
      End If
  End Select
   
End Function

To the dev's:
Why does MediaMonkey use a different program folder INI configuration file for the skinned and the non-skinned version? Do we need to use both (e.g. in the above function)? The INI filenames are made out of the filename of the MediaMonkey executable. Is there an easy way to get this executable filename (or don't we have to bother and always use "MediaMonkey.ini")?

Cheers
Steegy

Posted: Tue Jan 31, 2006 10:22 am
by mockturtle
Re. Ini file - the real ini file is stored in My Music\MediaMonkey folder, those created in MM folder are created by WinAmp compatible plug-ins (they use MM executable name as the base name for their .ini file and thus there are separate versions for skinned and non-skinned MM).

Re. Script.Include - it wouldn't help much to load only one method from a file, the main tasks (read content of the file and parse the file in order to find the function) would have to be done anyway. The delay won't be terrible, I just wanted to warn scripters to not include several thousands lines of scripts in each script they write.

Jiri

Posted: Tue Jan 31, 2006 10:39 am
by trixmoto
Personally I have a long text file with useful methods which I use, but I always copy and paste them into a script if I need them. I thinik most script users (who are not script writers) prefer to have a single script file as it is easier for them to install.

The ini path function is definitely better now as it should always find the main ini file.

Posted: Tue Jan 31, 2006 11:34 am
by Teknojnky
I wish MM would store all configuration data within its program directory instead of using the windows method of storing them in the user profiles.

Ideally, you could still keep separate user ini files, under a mediamonkey\user folder if so desired.

this would help imensely those who run MM from a shared location, like a network drive or an external drive/mp3 player.

Posted: Tue Jan 31, 2006 12:34 pm
by Steegy
Re. Ini file - the real ini file is stored in My Music\MediaMonkey folder, those created in MM folder are created by WinAmp compatible plug-ins (they use MM executable name as the base name for their .ini file and thus there are separate versions for skinned and non-skinned MM).
So what I'm been told about "use the one with the biggest size" and the "shared environment" stuff isn't true? We should only use the SDB.MyMusicPath & "MediaMonkey\MediaMonkey.ini" one then?

Cheers
Steegy

Posted: Tue Jan 31, 2006 1:28 pm
by trixmoto
I don't have a My Music folder, so this wouldn't work for me. I don't even have a MediaMonkey.ini file on my computer. Mine is stored here: "F:\Applications\MediaMonkey\MediaMonkey.ini"

If you create MediaMonkey.ini in the same folder as your MediaMonkey.exe then this one will override the one in your my music folder. Presumably on a key-by-key basis. But I just moved the .ini file and a new one was never created in my music, but the one in the program folder is always updating.

Posted: Tue Jan 31, 2006 3:40 pm
by Steegy
OK, I just refreshed my Readme-knowledge:
If you wish to share MediaMonkey's configuration file and or database among multiple users:
i) Move the MediaMonkey.ini file to the \Program Files\MediaMonkey directory.
The comparation of file sizes between different ini files can't be the right way. If you copy MyMusicINI to ProgramINI and then delete your 100 magic nodes, the ProgramINI files would be smaller than the other one. Therefor, the script would "detect" MyMusicINI as larger and would use that one. But that is wrong because MediaMonkey would be using the ProgramINI one.

How does MediaMonkey decide which INI to use? Does it first check the INI in the program folder for the [system] section? And if it doesn't find the [system] section, it uses the one in MyMusic subfolder?

Cheers
Steegy