Page 1 of 1

CloneVDI for VirtualBox users...

Posted: Sun Sep 14, 2008 6:19 pm
by blueznl
A quick and simple hack to clone those VDI images... just a GUI wrapper for vboxmanage.exe, I hate to type in those long lines every time :-)

Hmmm. What's the best (read: easiest :-)) way to store data in the application data folder? That's the way it should be done I guess...

Code: Select all

clonevdi_path.s = GetPathPart(ProgramFilename())
OpenPreferences(clonevdi_path+"clonevdi.cfg")
;
vdi_path.s = ReadPreferenceString("vdi_path","")
virtualbox_path.s = ReadPreferenceString(virtualbox_path,"c:\program files\sun\xvm virtualbox\")
ClosePreferences()
;
create_prefs = #False
If virtualbox_path = "" Or FileSize(virtualbox_path+"vboxmanage.exe") < 0
  virtualbox_path = GetPathPart(OpenFileRequester("CloneVDI - Select vboxmanage.exe","c:\","Executable|*.exe",0))
EndIf
;
If FileSize(virtualbox_path+"vboxmanage.exe") > 0
  Repeat
    vdi_source.s = OpenFileRequester("CloneVDI - Select source",vdi_path,"Virtual Disks|*.vdi|All|*.*",0)
    If vdi_source <> ""
      vdi_destination.s = SaveFileRequester("CloneVDI - Select destination",vdi_path,"Virtual Disks|*.vdi|All|*.*",0)
      If LCase(Right(vdi_destination,4)) <> ".vdi"
        vdi_destination = vdi_destination+".vdi"
      EndIf
      If vdi_source = vdi_destination
        result = MessageRequester("CloneVDI - Failed!","Source and destination cannot be the same!",#PB_MessageRequester_Ok|#MB_ICONWARNING)
      Else
        If FileSize(vdi_destination) > -1
          result = MessageRequester("CloneVDI - Please confirm.","The file "+vdi_destination+" already exists. Overwrite?",#PB_MessageRequester_YesNo|#MB_ICONWARNING)
          If result = #PB_MessageRequester_No
            vdi_destination.s = ""
          Else
            DeleteFile(vdi_destination)
          EndIf
        EndIf
        If vdi_destination <> ""
          ;
          RunProgram(virtualbox_path+"vboxmanage.exe","clonevdi "+#DQUOTE$+vdi_source+#DQUOTE$+" "+#DQUOTE$+vdi_destination+#DQUOTE$,virtualbox_path,#PB_Program_Wait)
          ;
          If FileSize(clonevdi_path+"clonevdi.prefs") < 0
            OpenPreferences(clonevdi_path+"clonevdi.prefs")
            WritePreferenceString("vdi_path",GetPathPart(vdi_source))
            WritePreferenceString("virtualbox_path",virtualbox_path)
            ClosePreferences()
          EndIf
          ;
        EndIf
      EndIf
    EndIf
  Until vdi_source = ""
EndIf