folder to iso (vista , xp/sp2 + KB932716 !)

Share your advanced PureBasic knowledge/code with the community.
User avatar
bingo
Enthusiast
Enthusiast
Posts: 210
Joined: Fri Apr 02, 2004 12:21 pm
Location: germany/thueringen
Contact:

folder to iso (vista , xp/sp2 + KB932716 !)

Post by bingo »

for testing edit the line:

isofile.s = "c:\tmp\mein.iso"
foldertoiso.s = "c:\temp\"
:D

Code: Select all

Import "shlwapi.lib" 
SHCreateStreamOnFileEx(pszFile.p-unicode,grfMode.l,dwAttributes.l,fCreate.b,pstmTemplate.l,ppstm.l); 
EndImport 

Interface IBootOptions ; Boot options 
  QueryInterface(riid.l,ppvObj.l) 
  AddRef() 
  Release() 
  GetTypeInfoCount(pctinfo.l) 
  GetTypeInfo(itinfo.l,lcid.l,pptinfo.l) 
  GetIDsOfNames(riid.l,rgszNames.l,cNames.l,lcid.l,rgdispid.l) 
  Invoke(dispidMember.l,riid.l,lcid.l,wFlags.l,pdispparams.l,pvarResult.l,pexcepinfo.l,puArgErr.l) 
  get_BootImage(dispidMember.l) 
  get_Manufacturer(dispidMember.l) 
  put_Manufacturer(dispidMember.p-bstr) 
  get_PlatformId(dispidMember.l) 
  put_PlatformId(dispidMember.l) 
  get_Emulation(dispidMember.l) 
  put_Emulation(dispidMember.l) 
  get_ImageSize(dispidMember.l) 
  AssignBootImage(newVal.l) 
EndInterface 

Interface IFileSystemImage ; File system image 
  QueryInterface(riid.l,ppvObj.l) 
  AddRef() 
  Release() 
  GetTypeInfoCount(pctinfo.l) 
  GetTypeInfo(itinfo.l,lcid.l,pptinfo.l) 
  GetIDsOfNames(riid.l,rgszNames.l,cNames.l,lcid.l,rgdispid.l) 
  Invoke(dispidMember.l,riid.l,lcid.l,wFlags.l,pdispparams.l,pvarResult.l,pexcepinfo.l,puArgErr.l) 
  get_Root(dispidMember.l) 
  get_SessionStartBlock(dispidMember.l) 
  put_SessionStartBlock(dispidMember.l) 
  get_FreeMediaBlocks(dispidMember.l) 
  put_FreeMediaBlocks(dispidMember.l) 
  SetMaxMediaBlocksFromDevice(discRecorder.l) 
  get_UsedBlocks(discRecorder.l) 
  get_VolumeName(discRecorder.l) 
  put_VolumeName(discRecorder.p-bstr) 
  get_ImportedVolumeName(discRecorder.l) 
  get_BootImageOptions(discRecorder.l) 
  put_BootImageOptions(discRecorder.l) 
  get_FileCount(discRecorder.l) 
  get_DirectoryCount(discRecorder.l) 
  get_WorkingDirectory(discRecorder.l) 
  put_WorkingDirectory(discRecorder.p-bstr) 
  get_ChangePoint(discRecorder.l) 
  get_StrictFileSystemCompliance(discRecorder.l) 
  put_StrictFileSystemCompliance(discRecorder.w) 
  get_UseRestrictedCharacterSet(discRecorder.l) 
  put_UseRestrictedCharacterSet(discRecorder.w) 
  get_FileSystemsToCreate(discRecorder.l) 
  put_FileSystemsToCreate(discRecorder.l) 
  get_FileSystemsSupported(discRecorder.l) 
  put_UDFRevision(discRecorder.l) 
  get_UDFRevision(discRecorder.l) 
  get_UDFRevisionsSupported(discRecorder.l) 
  ChooseImageDefaults(discRecorder.l) 
  ChooseImageDefaultsForMediaType(value.l) 
  put_ISO9660InterchangeLevel(value.l) 
  get_ISO9660InterchangeLevel(value.l) 
  get_ISO9660InterchangeLevelsSupported(value.l) 
  CreateResultImage(a.l) 
  Exists(FullPath.p-bstr) 
  CalculateDiscIdentifier() 
  IdentifyFileSystemsOnDisc(discRecorder.l) 
  GetDefaultFileSystemForImport(fileSystems.l) 
  ImportFileSystem() 
  ImportSpecificFileSystem(fileSystemToUse.l) 
  RollbackToChangePoint(ChangePoint.l) 
  LockInChangePoint() 
  CreateDirectoryItem(Name.p-bstr) 
  CreateFileItem(Name.p-bstr) 
  get_VolumeNameUDF(Name.l) 
  get_VolumeNameJoliet(Name.l) 
  get_VolumeNameISO9660(Name.l) 
  get_StageFiles(Name.l) 
  put_StageFiles(Name.w) 
  get_MultisessionInterfaces(Name.l) 
  put_MultisessionInterfaces(Name.l) 
EndInterface 

Interface IFileSystemImageResult ; FileSystemImage result stream 
  QueryInterface(riid.l,ppvObj.l) 
  AddRef() 
  Release() 
  GetTypeInfoCount(pctinfo.l) 
  GetTypeInfo(itinfo.l,lcid.l,pptinfo.l) 
  GetIDsOfNames(riid.l,rgszNames.l,cNames.l,lcid.l,rgdispid.l) 
  Invoke(dispidMember.l,riid.l,lcid.l,wFlags.l,pdispparams.l,pvarResult.l,pexcepinfo.l,puArgErr.l) 
  get_ImageStream(dispidMember.l) 
  get_ProgressItems(dispidMember.l) 
  get_TotalBlocks(dispidMember.l) 
  get_BlockSize(dispidMember.l) 
  get_DiscId(dispidMember.l) 
EndInterface 

Interface IFsiDirectoryItem ; FileSystemImage directory item 
  QueryInterface(riid.l,ppvObj.l) 
  AddRef() 
  Release() 
  GetTypeInfoCount(pctinfo.l) 
  GetTypeInfo(itinfo.l,lcid.l,pptinfo.l) 
  GetIDsOfNames(riid.l,rgszNames.l,cNames.l,lcid.l,rgdispid.l) 
  Invoke(dispidMember.l,riid.l,lcid.l,wFlags.l,pdispparams.l,pvarResult.l,pexcepinfo.l,puArgErr.l) 
  get_Name(dispidMember.l) 
  get_FullPath(dispidMember.l) 
  get_CreationTime(dispidMember.l) 
  put_CreationTime(dispidMember.d) 
  get_LastAccessedTime(dispidMember.l) 
  put_LastAccessedTime(dispidMember.d) 
  get_LastModifiedTime(dispidMember.l) 
  put_LastModifiedTime(dispidMember.d) 
  get_IsHidden(dispidMember.l) 
  put_IsHidden(dispidMember.w) 
  FileSystemName(fileSystem.l) 
  FileSystemPath(fileSystem.l) 
  get__NewEnum(fileSystem.l) 
  get_Item(path.p-bstr) 
  get_Count(path.l) 
  get_EnumFsiItems(path.l) 
  AddDirectory(path.p-bstr) 
  AddFile(path.p-bstr,fileData.l) 
  AddTree(sourceDirectory.p-bstr,includeBaseDirectory.w) 
  Add(Item.l) 
  Remove(path.p-bstr) 
  RemoveTree(path.p-bstr) 
EndInterface 

Structure STATSTG  
pwcsName.l 
type.l 
cbSize.q 
mtime.FILETIME 
ctime.FILETIME 
atime.FILETIME 
grfMode.f 
grfLocksSupported.l 
clsid.GUID 
grfStateBits.l 
reserved.l 
EndStructure 

Procedure.l Ansi2Uni(ansi.s) 
SHStrDup_(@ansi,@memziel) 
ProcedureReturn memziel 
EndProcedure 

#STGM_WRITE = 1 
#STGM_CREATE = $1000 
#STATFLAG_NONAME = 0 

#FsiFileSystemNone = 0 
#FsiFileSystemISO9660 = 1 
#FsiFileSystemJoliet = 2 
#FsiFileSystemUDF = 4 
#FsiFileSystemUnknown = 1073741824 

isostream.IStream 
datastream.IStream 

isofile.s = "c:\tmp\mein.iso" 
foldertoiso.s = "c:\temp\" 

CreateStreamOnHGlobal_(0,#True,@datastream) 
SHCreateStreamOnFileEx(isofile ,#STGM_WRITE|#STGM_CREATE,0,0,0,@isoStream) 

CoInitialize_(0) 
If CoCreateInstance_(?CLSID_BootOptions,0,1,?IID_IBootOptions,@object_boot.IBootOptions) = 0 
object_boot\put_Manufacturer("Microsoft") 
object_boot\put_PlatformId(0) ;x86 family processor 
object_boot\put_Emulation(0)  ;EmulationType.EmulationNone 
;... 

If CoCreateInstance_(?CLSID_FileSystemImage,0,1,?IID_IFileSystemImage,@object_fsimage.IFileSystemImage) = 0 

object_fsimage\put_FreeMediaBlocks(0) ;Enables larger-than-CD image 
object_fsimage\put_FileSystemsToCreate(#FsiFileSystemJoliet) 
object_fsimage\put_VolumeName("my iso") 
object_fsimage\put_BootImageOptions(object_boot.IBootOptions) 

object_fsimage\get_root(@object_fsidir.IFsiDirectoryItem) 

Debug object_fsidir\AddTree(foldertoiso,#VARIANT_TRUE) 
Debug object_fsidir\get_count(@dirinroot.l) 
Debug dirinroot ;1 

object_fsimage\CreateResultImage(@result.IFileSystemImageResult) 

result\get_ImageStream(@datastream) 

dataStream\Stat(st.STATSTG,#STATFLAG_NONAME) 
Debug "size: " + Str(st\cbSize) + " bytes" 

ret1.q 
ret2.q 

datastream\copyto(isostream,st\cbSize,@ret1,@ret2) 

Debug ret1 
Debug ret2 

object_fsimage\release() 
EndIf 

object_boot\Release() 
EndIf 

object_fsidir\release() 
isostream\release() 
datastream\release() 

CoUninitialize_() 

End 

DataSection 
CLSID_FileSystemImage: 
Data.l $2C941FC5 
Data.w $975B,$59BE 
Data.b $A9,$60,$9A,$2A,$26,$28,$53,$A5 
IID_IFileSystemImage: 
Data.l $2C941FE1 
Data.w $975B,$59BE 
Data.b $A9,$60,$9A,$2A,$26,$28,$53,$A5 
CLSID_BootOptions: 
Data.l $2C941FCE 
Data.w $975B,$59BE 
Data.b $A9,$60,$9A,$2A,$26,$28,$53,$A5 
IID_IBootOptions: 
Data.l $2C941FD4 
Data.w $975B,$59BE 
Data.b $A9,$60,$9A,$2A,$26,$28,$53,$A5 
EndDataSection
["1:0>1"]
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

That's pretty cool. Thanks for the code.
Could that work for compressed ISO (isz) files as well?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Compressed iso (isz) is an open format created by the makers of Ultra ISO and is not supported natively by the Windows OS.

http://www.ezbsystems.com/isz/iszspec.txt
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

I read somewhere that if you create an ISO and use Vista build-in stuff for that the resulting ISO can't be read on Linux.
Is this true?

Don't have Vista myself, so I can't test it...
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Compressed iso (isz) is an open format created by the makers of Ultra ISO and is not supported natively by the Windows OS.
Hello, good job BINGO
but is it the reason why, i have an error at the line 210 :roll: :

Code: Select all

object_fsidir\release() 
I have XP Sp2, Pb v4.10 Beta
ImageThe happiness is a road...
Not a destination
DataMiner
User
User
Posts: 25
Joined: Mon Mar 28, 2005 1:29 pm
Location: Germany

Post by DataMiner »

@Kwaï chang caïne
On XP sp2 you have to install KB932716 (Image Mastering API v2.0) first.
I am German - that's hard enough ;)
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Pretty nifty!
Dare2 cut down to size
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

This is very nice, Thank You :)

Is there some way to get an indication when the iso creation and write to the destination is complete?

how do you add a file with it? AddFile? can't get AddFile to work.
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: folder to iso (vista , xp/sp2 + KB932716 !)

Post by Seymour Clufley »

I'm running this on XP SP2 (with the KB932716 hotfix installed). An ISO is created with a filesize that seems about right. But when I open the ISO (with WinRAR and with PowerISO), nothing is inside it. Or at least, nothing gets extracted from it.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: folder to iso (vista , xp/sp2 + KB932716 !)

Post by SFSxOI »

you might look here where I did basically the entire IMAPI thing > http://www.purebasic.fr/english/viewtop ... ilit=IMAPI

Part of this is included, works fine here. Might help. It might be that your not actually adding files to the .iso
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Post Reply