private void buttonStartAbort_Click(object sender, EventArgs e) { if (m_thread == null || !m_thread.IsAlive) { if (textBoxVolumeName.Text.Trim() != "") { m_thread = new Thread(new ParameterizedThreadStart(m_creator.Tree2Iso)); BER.CDCat.Export.TreeNode volume = this.TreeView2TreeNode(this.treeView1); m_thread.Start(new IsoCreator.IsoCreatorTreeArgs(volume, textBoxIsoPath.Text)); buttonStartAbort.Text = "Abort"; } else { MessageBox.Show("Please insert a name for the volume", "No volume name", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } else { if (MessageBox.Show("Are you sure you want to abort the process?", "Abort", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { m_thread.Abort(); } } }
private BER.CDCat.Export.TreeNode TreeView2TreeNode(TreeView treeView) { BER.CDCat.Export.TreeNode root = new BER.CDCat.Export.TreeNode(); root.Name = textBoxVolumeName.Text; root.ShortName = textBoxVolumeName.Text.ToUpper(); root.IsDirectory = true; root.CreationTime = DateTime.Now; foreach (System.Windows.Forms.TreeNode node in treeView.Nodes) { BER.CDCat.Export.TreeNode child = new BER.CDCat.Export.TreeNode(); child.Name = node.Text; child.Length = 10; child.IsDirectory = (node.Nodes.Count > 0); child.CreationTime = DateTime.Now; if (child.IsDirectory) { root.Directories.Add(child); GetTreeNodeFromNode(child, node); } else { root.Files.Add(child); } } // return(root); }
public IsoFolderElement( TreeNode folderElement, bool isRoot, string childNumber ) { m_date = folderElement.CreationTime; m_identifier = folderElement.Name; if ( isRoot ) { m_shortIdent = "."; m_identifier = "."; } else { if ( m_identifier.Length > 8 ) { m_shortIdent = m_identifier.Substring( 0, 8 - childNumber.Length ).ToUpper().Replace( ' ', '_' ).Replace( '.', '_' ); m_shortIdent += childNumber; } else { m_shortIdent = m_identifier.ToUpper().Replace( ' ', '_' ).Replace( '.', '_' ); } } if ( m_identifier.Length > IsoAlgorithm.FileNameMaxLength ) { m_identifier = m_identifier.Substring( 0, IsoAlgorithm.FileNameMaxLength - childNumber.Length ) + childNumber; } }
private void GetTreeNodeFromNode(BER.CDCat.Export.TreeNode dir, System.Windows.Forms.TreeNode node) { foreach (System.Windows.Forms.TreeNode nodeChild in node.Nodes) { BER.CDCat.Export.TreeNode child = new BER.CDCat.Export.TreeNode(); child.Name = nodeChild.Text; child.Length = 10; child.IsDirectory = (nodeChild.Nodes.Count > 0); child.CreationTime = DateTime.Now; if (child.IsDirectory) { GetTreeNodeFromNode(child, nodeChild); dir.Directories.Add(child); } else { dir.Files.Add(child); } } }
/// <summary> /// Writes an ISO with the contains of the tree given as a parameter, to the specified path. /// </summary> /// <param name="volume">The directory structure to be turned into an iso.</param> /// <param name="isoPath">The path of the iso file to be created.</param> public void Tree2Iso(BER.CDCat.Export.TreeNode volume, string isoPath) { try { FileStream isoFileStream = new FileStream(isoPath, FileMode.Create); BinaryWriter writer = new BinaryWriter(isoFileStream); try { this.Tree2Iso(volume, writer); writer.Close(); isoFileStream.Close(); this.OnFinished("ISO writing process finished succesfully"); } catch (Exception ex) { writer.Close(); isoFileStream.Close(); throw ex; } } catch (System.Threading.ThreadAbortException ex) { System.Diagnostics.Debug.WriteLine(ex.Message); this.OnAbort("Aborted by user"); } catch (Exception ex) { this.OnAbort(ex.Message); } }
public IsoCreatorTreeArgs(BER.CDCat.Export.TreeNode volume, string isoPath) { m_volume = volume; m_isoPath = isoPath; }
/// <summary> /// Writes an ISO with the contains of the tree given as a parameter. /// This is a "virtual" ISO, which means that you will find on it only a directory structure; /// files will actually not ocupy any space on it. (For a better picture of what happens here, /// run the VirtualIsoCreator form in Forms namespace. There is a demo. Also, if you have CDCat /// installed on your PC, you should know by now the effect of the method below. Within CDCat, /// this method is used through the ExportIso class in BER.CDCat.Export namespace) /// </summary> /// <param name="volume">The directory structure to be turned into an iso.</param> /// <param name="writer">A binary writer to write the data.</param> private void Tree2Iso(BER.CDCat.Export.TreeNode volume, BinaryWriter writer) { ArrayList dirList; IsoDirectory[] dirArray; this.OnProgress("Initializing ISO root directory...", 0, 1); IsoDirectory root = new IsoDirectory(volume, 1, "0", Progress); // // Folder structure and path tables corresponding to the Primary Volume Descriptor: // this.OnProgress("Preparing first set of directory extents...", 0, 1); dirList = new ArrayList(); dirList.Add(root); // Set all extents corresponding to the primary volume descriptor; // Memorize the SORTED directories in the dirList list. // The first extent (corresponding to the root) should be at the 19th sector // (which is the first available sector: 0-15 are empty and the next 3 (16-18) // are occupied by the volume descriptors). IsoDirectory.SetExtent1(dirList, 0, 19); this.OnProgress(1); this.OnProgress("Calculating directory numbers...", 0, 1); dirArray = new IsoDirectory[dirList.Count]; dirList.ToArray().CopyTo(dirArray, 0); // Copy to an array the sorted directory list. this.SetDirectoryNumbers(dirArray); // Set the directory numbers, used in the path tables. this.OnProgress(1); this.OnProgress("Preparing first set of path tables...", 0, 2); // Create a memory stream where to temporarily save the path tables. // (We can't write them directly to the file, because we first have to write - by convention - // the directories. For now, we cannot do that, since we don't know the files' extents. // Those will be calculated later, when we know the actual size of the path tables, because // the files come at the end of the file, after the path tables.) // I used this algorihm, although a little backword, since this is the algorithm NERO uses, // and I gave them credit for choosing the best one ;) MemoryStream memory1 = new MemoryStream(); BinaryWriter memoryWriter1 = new BinaryWriter(memory1); // Calculate the position of the first little endian path table, which comes right after the last directory. IsoDirectory lastDir = dirArray[dirArray.Length - 1]; UInt32 typeLPathTable1 = lastDir.Extent1 + lastDir.Size1 / IsoAlgorithm.SectorSize; this.WritePathTable(memoryWriter1, dirArray, Endian.LittleEndian, VolumeType.Primary); this.OnProgress(1); // Calculate the position of the first big endian path table. UInt32 typeMPathTable1 = typeLPathTable1 + (UInt32)(memory1.Length) / IsoAlgorithm.SectorSize; UInt32 pathTableSize1 = (UInt32)this.WritePathTable(memoryWriter1, dirArray, Endian.BigEndian, VolumeType.Primary); this.OnProgress(2); // // end // // // Folder structure and path tables corresponding to the Suplementary Volume Descriptor: // this.OnProgress("Preparing second set of directory extents...", 0, 1); dirList = new ArrayList(); dirList.Add(root); UInt32 currentExtent = typeLPathTable1 + (UInt32)(memory1.Length) / IsoAlgorithm.SectorSize; IsoDirectory.SetExtent2(dirList, 0, currentExtent); dirArray = new IsoDirectory[dirList.Count]; dirList.ToArray().CopyTo(dirArray, 0); this.OnProgress(1); this.OnProgress("Preparing second set of path tables...", 0, 2); MemoryStream memory2 = new MemoryStream(); BinaryWriter memoryWriter2 = new BinaryWriter(memory2); lastDir = dirArray[dirArray.Length - 1]; UInt32 typeLPathTable2 = lastDir.Extent2 + lastDir.Size2 / IsoAlgorithm.SectorSize; this.WritePathTable(memoryWriter2, dirArray, Endian.LittleEndian, VolumeType.Suplementary); this.OnProgress(1); UInt32 typeMPathTable2 = typeLPathTable2 + (UInt32)(memory2.Length) / IsoAlgorithm.SectorSize; UInt32 pathTableSize2 = (UInt32)this.WritePathTable(memoryWriter2, dirArray, Endian.BigEndian, VolumeType.Suplementary); this.OnProgress(2); // // end // this.OnProgress("Initializing...", 0, 1); // Now that we know the extents and sizes of all directories and path tables, // all that remains is to calculate files extent. However, this being a virtual ISO, // it won't memorize real files, but only images of files, which will apear to have a real size, // but in fact, won't occupy any more space. So we will leave all the files' extents null (0). // Calculate the total size in sectors of the file to be made. UInt32 volumeSpaceSize = 19; volumeSpaceSize += root.TotalDirSize; // This only calculates the size of the directories, without the files. volumeSpaceSize += (UInt32)memory1.Length / IsoAlgorithm.SectorSize; volumeSpaceSize += (UInt32)memory2.Length / IsoAlgorithm.SectorSize; // Prepare the buffers for the path tables. byte[] pathTableBuffer1 = memory1.GetBuffer(); Array.Resize(ref pathTableBuffer1, (int)memory1.Length); byte[] pathTableBuffer2 = memory2.GetBuffer(); Array.Resize(ref pathTableBuffer2, (int)memory2.Length); // Close the memory streams. memory1.Close(); memory2.Close(); memoryWriter1.Close(); memoryWriter2.Close(); this.OnProgress(1); // // Now all we have to do is to write all information to the ISO: // this.OnProgress("Writing data to file...", 0, (int)volumeSpaceSize); // First, write the 16 empty sectors. this.WriteFirst16EmptySectors(writer); this.OnProgress((int)(writer.BaseStream.Length / IsoAlgorithm.SectorSize)); // Write the three volume descriptors. this.WriteVolumeDescriptors( writer, volume.Name, root, volumeSpaceSize, pathTableSize1, pathTableSize2, typeLPathTable1, typeMPathTable1, typeLPathTable2, typeMPathTable2); this.OnProgress((int)(writer.BaseStream.Length / IsoAlgorithm.SectorSize)); // Write the directories in a manner corresponding to the Primary Volume Descriptor. this.WriteDirectories(writer, dirArray, VolumeType.Primary); // Write the first two path tables. writer.Write(pathTableBuffer1); this.OnProgress((int)(writer.BaseStream.Length / IsoAlgorithm.SectorSize)); // Write the directories in a manner corresponding to the Suplementary Volume Descriptor. this.WriteDirectories(writer, dirArray, VolumeType.Suplementary); // Write the other two path tables. writer.Write(pathTableBuffer2); this.OnProgress((int)(writer.BaseStream.Length / IsoAlgorithm.SectorSize)); // If this were an ISO with real files, this is the part where we would write the files. // That's it ;) }
private BER.CDCat.Export.TreeNode TreeView2TreeNode( TreeView treeView ) { BER.CDCat.Export.TreeNode root = new BER.CDCat.Export.TreeNode(); root.Name = textBoxVolumeName.Text; root.ShortName = textBoxVolumeName.Text.ToUpper(); root.IsDirectory = true; root.CreationTime = DateTime.Now; foreach ( System.Windows.Forms.TreeNode node in treeView.Nodes ) { BER.CDCat.Export.TreeNode child = new BER.CDCat.Export.TreeNode(); child.Name = node.Text; child.Length = 10; child.IsDirectory = ( node.Nodes.Count > 0 ); child.CreationTime = DateTime.Now; if ( child.IsDirectory ) { root.Directories.Add( child ); GetTreeNodeFromNode( child, node ); } else { root.Files.Add( child ); } } // return root; }
private void GetTreeNodeFromNode( BER.CDCat.Export.TreeNode dir, System.Windows.Forms.TreeNode node ) { foreach ( System.Windows.Forms.TreeNode nodeChild in node.Nodes ) { BER.CDCat.Export.TreeNode child = new BER.CDCat.Export.TreeNode(); child.Name = nodeChild.Text; child.Length = 10; child.IsDirectory = ( nodeChild.Nodes.Count > 0 ); child.CreationTime = DateTime.Now; if ( child.IsDirectory ) { GetTreeNodeFromNode( child, nodeChild ); dir.Directories.Add( child ); } else { dir.Files.Add( child ); } } }
public int Add( TreeNode node ) { return this.InnerList.Add( node ); }
public void Remove( TreeNode node ) { this.InnerList.Remove( node ); }
public IsoFile( TreeNode file, string childNumber ) : base( file, false, childNumber ) { m_fullPath = file.FullName; m_size = (UInt32)file.Length; }
public IsoCreatorTreeArgs( BER.CDCat.Export.TreeNode volume, string isoPath ) { m_volume = volume; m_isoPath = isoPath; }