Home Technical Talk

Maxscript making a self installing mzp

Kingblue
polycounter lvl 8
Offline / Send Message
Kingblue polycounter lvl 8
I've made my first script. I've searched the help but really couldn't find a method to
declare folders, how to make my ms script a mzp self installing file and so on. The sources I've read say different things (for example the path to place the ms file in).
Any suggestion would really help me shed some light on the problem.

Replies

  • monster
    Options
    Offline / Send Message
    monster polycounter
    If it's just a single file I would just make it available for download.

    An MZP file is a zip file with the extension renamed. The easiest method I've found to use MZP files is to have it launch another maxscript and then let that finish the work. Inside the MZP file you should have a file named mzp.run with contents similar to this:
    name "My Tool"
    version 1.0
    
    extract to $temp\mytool
    
    run installer_mytool.ms
    drop installer_mytool.ms
    
    clear temp on MAX exit
    

    The mzp.run file is capable of doing more operations, but I haven't had much success with that. That's why I just have it run another MaxScript. You can have installer_mytool.ms delete any previous verion, copy the script to the proper location, evaluate the file, and finally prompt that installation failed or was successful.
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    Go here and dlownload RTTAssist_1.6.mzp
    Unzip the mzp in separate folder. You will find all files that monster mentoined. The install.ms uses some DOS commands and creates new folders, move the ms, mcr. and icon files etc.
    Also, you can download ToTex and take a look into his install.ms file - HiddenDOSCommand is used.
    Oitliner ver 2 have installe.ms that is use dotNet for createing folders.
    Get what is best for you and use it.
    :)

    P.S. you can use the mzp.run to create folders and move the files, but in Win Vista, Win7, you have to ruun the max and the MZP as adnimistrator.
  • Kingblue
    Options
    Offline / Send Message
    Kingblue polycounter lvl 8
    Ok, I'm starting to make some order in my mind. Here are the steps that I've traced so far.

    1. Put your script and icon files in a zip file and rename it to mzp.
    2. Write a text file with instructions to copy the folder contained in the mzp file to windows temp directory. You can't
    do it directly,you must delegate another ms.file (already stored in the mzp file). Save this as mzp.run
    Example

    name "John Doe"

    Version Beta

    extract to $temp/johndoe
    run "johndoeinstaller.ms"
    drop "johndoeinstaller.ms"

    clear temp


    3.Compile the delegate johndoeinstaller.ms file that shall do the installation operations like copying files and so on. Here I'm lost again.
    Can you suggest some info on this?
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    Did you examine the code of the installers, that I mentioned above?
    For exampel RTTAssist installer:
    the mzp.run code
    name "RTTAssist"
    version 1.6
    
    treeMove "tempRTTAssistFolder" to "$temp"
    
    run "RTTAssistInstall.ms"
    drop "RTTAssistInstall.ms"
    
    clear temp
    
    The RTTAssistInstall file that do the installation - copy files, create directories.
    --******************************************************************************************************
    -- Created:         12-06-2011
    -- Last Updated:    25-07-2011
    --
    -- Author :  Kostadin Kotev / miau_u@yahoo.com /
    -- Version:  3ds max 2009 and up
    --
    -- Discription: 
    --    RTTAssist Install file
    --******************************************************************************************************
    -- MODIFY THIS AT YOUR OWN RISK
    
    (
        global RTTAssist_Instalation
        try ( destroyDialog RTTAssist_Instalation ) catch ()
        try ( destroyDialog miauuRTTassist ) catch ()
        rollout RTTAssist_Instalation "RTTAssist 1.6 Setup"
        (
            local tempRTTAssistFolder = pathConfig.GetDir #temp+"\\tempRTTAssistFolder"
            local usRTTAui = pathConfig.GetDir #userscripts+"\\RTTAssistUI"
            local usRTTAuiIco = pathConfig.GetDir #userscripts+"\\RTTAssistUI\\RTTAssistIcons"
            local usRTTAuiPrst01 = pathConfig.GetDir #userscripts + "\\RTTAssist"
            local usRTTAuiPrst02 = pathConfig.GetDir #userscripts + "\\RTTAssist\\Presets"
            
            ImgTag ImgTag_BG bitmap:(bitmap 2 2 color:gray) pos:[0,0]  \
                width:309 height:194 opacity:1 transparent:(color 0 255 255) enabled:off
    
            hyperLink httpOficialSite "Oficial Site" pos:[213,138] color:(color 176 208 231) hoverColor:(color 82 129 181) visitedColor:(color 65 81 100) address:"http://vertexbee.com/rttassist.htm"
            hyperLink httpVideos "Videos" pos:[213,152] color:(color 176 208 231) hoverColor:(color 82 129 181) visitedColor:(color 65 81 100) address:"http://www.youtube.com/user/RTTassist?feature=mexp"
            ImgTag it_License bitmap:(bitmap 2 2 color:white) pos:[213,166]  \
                width:36 height:9 opacity:1 transparent:(color 0 255 255)
            
            button btn_Install "Install" width:138 height:30 pos:[30,103]
            button btn_Uninstall "Uninstall" width:138 height:30 pos:[30,145]
    
            
            function DeleteDirAndSubDir rootDir =
            (
                try ( DOSCommand ("rmDir \"" + rootDir + "\" /s /q") ) catch (messagebox "Can't delete RTTAssist folders!" title:"RTTAssist Install Error!!!")
            )
            function DeleteFiles curDir file =
            (
                filesToDelete = getFiles (curDir + file)
                for f in filesToDelete do    deleteFile f
            )
            
            function ValidateDirectory _dirNameIn  =
            (
                local _dirName = copy _dirNameIn
                local c
                for i = _dirName.count to 1 by -1 while (c=_dirName[i]; c=="\\" or c== "/") do
                    _dirName = subString _dirName 1 (i-1)
                
                if doesFileExist _dirName then
                    dirExists = true
                else
                    dirExists = false
                
                return dirExists
            )
            function InstalRTTAssist =
            (
                if tempRTTAssistFolder != "" then
                (
                    --    create main, icons and preset folders
                    local rttAssistMainFolder = (makeDir usRTTAui)
                    local iconFolder = (makeDir usRTTAuiIco)
                    local presetFolder01 = (makeDir usRTTAuiPrst01)
                    local presetFolder02 = (makeDir usRTTAuiPrst02)
                    
                    if presetFolder02 != true then
                    (
                        messagebox "Unable to create \"Preset\" folder" title:"RTTAssist Installation Error!!!"
                    )
                    else
                    (
                        --    copy icons and UI files
                        if iconFolder == true then
                        (
                            allPreinstPNGfiles = (getFiles (tempRTTAssistFolder+"\\RTTAssistUI\\RTTAssistIcons\\*.png"))
                            for pngFile in allPreinstPNGfiles do
                            (        
                                copyFile pngFile (usRTTAui+"\\RTTAssistIcons\\"+filenameFromPath pngFile)
                            )
                            allInstalledPNGfiles = (getFiles (usRTTAui+"\\RTTAssistIcons\\*.png"))                        
                            if allInstalledPNGfiles.count != allPreinstPNGfiles.count do messagebox "Installation Error!!!" title:"RTTAsssist"
                        )
                        else
                            messagebox "Unable to create \"RTTAssist Icons\" folder" title:"RTTAssist Installation Error!!!"
                        --    copy htm, ini, license and ms files
                        if rttAssistMainFolder == true then
                        (        
                            allPreinstMCIfiles = (getFiles (tempRTTAssistFolder+"\\RTTAssistUI\\*.*"))
                            for mciFile in allPreinstMCIfiles do
                            (    
                                copyFile mciFile (usRTTAui+"\\"+filenameFromPath mciFile)                        
                            )
                            allInstalledMCIfiles = (getFiles (usRTTAui+"\\*.*"))                        
                            if allInstalledMCIfiles.count != allPreinstMCIfiles.count do messagebox "Installation Error!!!" title:"RTTAsssist"
                        )
                        else
                            messagebox "Unable to create main \"RTTAssist\" folder" title:"RTTAssist Installation Error!!!"
                        --    copy toolbar Icons
                        for tBarIcoFiles in (getFiles (tempRTTAssistFolder+"\\icons\\*.*")) do
                        (    
                            copyFile tBarIcoFiles (pathConfig.GetDir #userIcons+"\\"+filenameFromPath tBarIcoFiles)
                        )
                        --    copy RTTAssist macro
                        if (copyFile (tempRTTAssistFolder+"\\Macro_RTTAssist.mcr") (usRTTAui+"\\Macro_RTTAssist.mcr")) then
                        (    --    load macro
                            fileIn (usRTTAui+"\\Macro_RTTAssist.mcr")
                             --    start RTTAssist
                            try(fileIn (usRTTAui+"\\RTTAssist.ms"))
                            catch(messagebox "Please, start RTTAssist manualy!" title:"RTTAssist")
                        )
                        else
                            messagebox "Can't copy the macro file of RTTAssist!" title:"RTTAssist Installation Error!!!"
                    )
                )
                else
                    messagebox "Insallation Error!!!" title:"RTTAsssist"
            )
            
            on RTTAssist_Instalation open do
            (
                if tempRTTAssistFolder != "" then 
                (
                    ImgTag_BG.bitmap = (openBitmap (tempRTTAssistFolder+"\\RTTAssistInstallBG.png"))
                    it_License.bitmap = (openBitmap (tempRTTAssistFolder+"\\miauuITlicense.png"))
                )
                
                if onlineUpdate == true do
                (
                    if (doesFileExist ((getDir #userscripts) + "\RTTAssistUI\RTTAssist.ms")) do
                    (                    
                        DeleteFiles ((getDir #userscripts) + "\RTTAssistUI") "*.*"    --    delete the ms, ini and help file
                        DeleteFiles ((getDir #userscripts) + "RTTAssistIcons") "*.*"    --    delete the icons
                        DeleteDirAndSubDir ((getDir #userscripts) + "\RTTAssistUI")    --    delete folders                    
                        DeleteFiles (getDir #userMacros) "*RTTAssist*.*"    --    delete macro
                        DeleteFiles ("$max\\ui\\macroscripts\\") "Macro_RTTAssist.mcr"
                    )
                    InstalRTTAssist()
                    destroydialog RTTAssist_Instalation
                )
            )
            on it_License lbuttondown do
            (
                licFile = tempRTTAssistFolder+"\license.html"
                shelllaunch licFile ""
            )
            on it_License mouseover do
            (
                it_License.bitmap = (openBitmap (tempRTTAssistFolder+"\\miauuITlicenseHover.png"))
            )
            on it_License mouseout do
            (
                it_License.bitmap = (openBitmap (tempRTTAssistFolder+"\\miauuITlicense.png"))
            )        
            on RTTAssist_Instalation close do
            (
                if tempRTTAssistFolder != "" then
                    DeleteDirAndSubDir tempRTTAssistFolder
            )
            
            on btn_Install pressed do
            (
                if tempRTTAssistFolder != "" then
                (
                    --    create RTTAssistUI directory
                    if (ValidateDirectory usRTTAui) == false then
                    (--    if RTTAssistUI folder does not exist start new installation
                        InstalRTTAssist()
                        destroydialog RTTAssist_Instalation
                    )
                    else
                    (--    if RTTAssistUI folder exist show upgrade dialog
                        try(destroyDialog ReinstallUpgrade)catch()
                        rollout ReinstallUpgrade "RTTAssist 1.6"
                        (
                            label lb1 "RTTassist has already been installed!" pos:[20,20]
                            label lb2 "To reinstall or update RTTAssist press \"Continue\"." pos:[20,40]
                            label lb "To cancel the operation press \"Cancel\"."    pos:[20,60]
                            
                            button btn_Continue "Continue" pos:[150,90] width:50
                            button btn_Cancel "Cancel" pos:[210,90] width:50
                            
                            on btn_Continue pressed do
                            (
                                if (doesFileExist ((getDir #userscripts) + "\RTTAssistUI\RTTAssist.ms")) or \
                                    (doesFileExist ((getDir #userscripts) + "\RTTAssistUI\RTTAssist.mse")) do
                                (                                
                                    DeleteFiles ((getDir #userscripts) + "\RTTAssistUI") "*.*"    --    delete the ms, ini and help file
                                    DeleteFiles ((getDir #userscripts) + "\RTTAssistIcons") "*.*"    --    delete the icons
                                    DeleteDirAndSubDir ((getDir #userscripts) + "\RTTAssistUI")    --    delete folders                                
                                    DeleteFiles ((getDir #userMacros) + "\\") "*RTTAssist*.*"    --    delete macro                                 
                                    DeleteFiles ("$max\\ui\\macroscripts\\") "Macro_RTTAssist.mcr"
                                )
                                InstalRTTAssist()
                                destroydialog ReinstallUpgrade
                                destroydialog RTTAssist_Instalation    
                            )
                            
                            on btn_Cancel pressed do
                            (
                                destroydialog ReinstallUpgrade
                            )
                        )
                        createdialog ReinstallUpgrade height:120 width:275 bgcolor:white fgcolor:red modal:true                        
                    )
                )
                else
                    messagebox "Insallation Error!!!" title:"RTTAsssist"
            )
            
            on btn_Uninstall pressed do
            (
                if (doesFileExist ((getDir #userscripts) + "\RTTAssistUI\RTTAssist.ms")) or \
                    (doesFileExist ((getDir #userscripts) + "\RTTAssistUI\RTTAssist.mse")) do
                (                
                    DeleteFiles ((getDir #userscripts) + "\RTTAssistUI") "*.*"    --    delete the ms, ini and help file
                    DeleteFiles ((getDir #userscripts) + "\RTTAssistIcons") "*.*"    --    delete the icons
                    DeleteDirAndSubDir ((getDir #userscripts) + "\RTTAssistUI")    --    delete folders                
                    DeleteFiles ((getDir #userscripts) + "\RTTAssist\Presets") "*.*"    --    delete the rpf and rps file
                    DeleteDirAndSubDir ((getDir #userscripts) + "\RTTAssist")    --    delete folders
                    DeleteFiles ((getDir #userMacros) + "\\") "*RTTAssist*.*"    --    delete macro                 
                    DeleteFiles ("$max\\ui\\macroscripts\\") "Macro_RTTAssist.mcr"
                    --    delete tempRTTAssistfolder
                    if (tempRTTAssistFolder != "") then
                        DeleteDirAndSubDir tempRTTAssistFolder
                    
                    destroydialog RTTAssist_Instalation
                    
                    rollout UninstallComplete "RTTAssist 1.6 Setup"
                    (
                        label lb1 "     Uninstallation complete." pos:[20,20]
                        label lb2 "Thank you for using RTTAssist." pos:[20,40]
                    )
                    createdialog UninstallComplete height:70 width:185 bgcolor:white fgcolor:black
                )
            )
        )
        createDialog RTTAssist_Instalation height:194 width:309 bgcolor:gray
    )
    
    This installer uses some DOS commands
    The Totex installer uses HiddenDosCommand
    The Outliner installer uses dotnet
    Just check the codes and use what is best for you
    :)
  • Kingblue
    Options
    Offline / Send Message
    Kingblue polycounter lvl 8
    I didn't think that copy and pasting files in Mxs was harder than making the script itself (being said that's my first script). Whew, I'll start deciphering it. Thanks
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Once you're an old pro like us, you'll have a build.ms that creates the mzp for you. :)
  • miauu
    Options
    Offline / Send Message
    miauu polycounter lvl 14
    Go here and check of this tool will help you to create the mzp with less efforts
  • Kingblue
    Options
    Offline / Send Message
    Kingblue polycounter lvl 8
    Thanks again, guys.
Sign In or Register to comment.