IDiskImagePolicy.CreateDMG( DiskImage sender, Bam.Core.ExecutionContext context, Bam.Core.ICommandLineTool compiler, Bam.Core.TokenizedString sourceFolderPath, Bam.Core.TokenizedString outputPath) { var volumeName = sender.CreateTokenizedString("$(OutputName)").Parse(); var tempDiskImagePathName = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString() + ".dmg"; // must have .dmg extension var diskImagePathName = outputPath.ToString(); var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); // create the disk image { var settings = sender.Settings as IDiskImageSettings; var args = new Bam.Core.StringArray(); args.Add("create"); args.AddRange(commandLine); args.Add("-srcfolder"); args.Add(System.String.Format("\"{0}\"", sourceFolderPath.ToString())); args.Add("-size"); args.Add(settings.ImageSize); args.Add("-fs"); args.Add("HFS+"); args.Add("-volname"); args.Add(System.String.Format("\"{0}\"", volumeName)); args.Add(tempDiskImagePathName); CommandLineProcessor.Processor.Execute(context, compiler, args); } // mount disk image { var args = new Bam.Core.StringArray(); args.Add("attach"); args.AddRange(commandLine); args.Add(tempDiskImagePathName); CommandLineProcessor.Processor.Execute(context, compiler, args); } // TODO /// do a copy // unmount disk image { var args = new Bam.Core.StringArray(); args.Add("detach"); args.AddRange(commandLine); args.Add(System.String.Format("\"/Volumes/{0}\"", volumeName)); CommandLineProcessor.Processor.Execute(context, compiler, args); } var dmgDir = System.IO.Path.GetDirectoryName(diskImagePathName); Bam.Core.IOWrapper.CreateDirectoryIfNotExists(dmgDir); // hdiutil convert myimg.dmg -format UDZO -o myoutputimg.dmg { var args = new Bam.Core.StringArray(); args.Add("convert"); args.AddRange(commandLine); args.Add(tempDiskImagePathName); args.Add("-format"); args.Add("UDZO"); args.Add("-o"); args.Add(diskImagePathName); CommandLineProcessor.Processor.Execute(context, compiler, args); } }
IDiskImagePolicy.CreateDMG( DiskImage sender, Bam.Core.ExecutionContext context, Bam.Core.ICommandLineTool compiler, Bam.Core.TokenizedString sourceFolderPath, Bam.Core.TokenizedString outputPath) { var volumeName = sender.CreateTokenizedString("$(OutputName)").Parse(); var tempDiskImagePathName = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString() + ".dmg"; // must have .dmg extension var diskImagePathName = outputPath.ToString(); var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); // create the disk image { var settings = sender.Settings as IDiskImageSettings; var args = new Bam.Core.StringArray(); args.Add("create"); args.AddRange(commandLine); args.Add("-srcfolder"); args.Add(System.String.Format("\"{0}\"", sourceFolderPath.ToString())); args.Add("-size"); args.Add(settings.ImageSize); args.Add("-fs"); args.Add("HFS+"); args.Add("-volname"); args.Add(System.String.Format("\"{0}\"", volumeName)); args.Add(tempDiskImagePathName); CommandLineProcessor.Processor.Execute(context, compiler, args); } // mount disk image { var args = new Bam.Core.StringArray(); args.Add("attach"); args.AddRange(commandLine); args.Add(tempDiskImagePathName); CommandLineProcessor.Processor.Execute(context, compiler, args); } // TODO /// do a copy // unmount disk image { var args = new Bam.Core.StringArray(); args.Add("detach"); args.AddRange(commandLine); args.Add(System.String.Format("\"/Volumes/{0}\"", volumeName)); CommandLineProcessor.Processor.Execute(context, compiler, args); } var dmgDir = System.IO.Path.GetDirectoryName(diskImagePathName); if (!System.IO.Directory.Exists(dmgDir)) { System.IO.Directory.CreateDirectory(dmgDir); } // hdiutil convert myimg.dmg -format UDZO -o myoutputimg.dmg { var args = new Bam.Core.StringArray(); args.Add("convert"); args.AddRange(commandLine); args.Add(tempDiskImagePathName); args.Add("-format"); args.Add("UDZO"); args.Add("-o"); args.Add(diskImagePathName); CommandLineProcessor.Processor.Execute(context, compiler, args); } }