October 3, 20241 yr Localization Hello, guys! I'm working on a great tool, and I really need your help. My program is operational, but there's a treeView1-related issue. The BoxBuilder form has some buttons. button1 is responsible for create a new -*.box archive. Button5 is responsible for add file(s) to treeView1 component. Button6 is responsible for make new folder (node) button7 is responsible for make subfolder (childnode) if a Node is selected. Problem: I can create the archive, but unable to open it... My other tool that uses listView1 component is working and the game can use the archive... Can you help me fixing my code? Attached I uploaded all the necessary files. I'm looking forward for your replies. Thank you very much in advance. The problem only can be found in the BoxBuilder.cs file Edited October 13, 20241 yr by Krisztian1990
October 5, 20241 yr Author Localization Solution Hello, guys again! I have updated my code, now it is 100% good for files, but still can not handle neither folders (created with button6) nor subfolders (created with button7).. Here's the fixed code below: private void WriteFilesToArchive(BinaryWriter writer, TreeNodeCollection nodes) { // List of metadata containing information about files and directories List<(string filename, long offset, int size)> metaDataList = new List<(string, long, int)>(); // Write content and collect metadata WriteContent(writer, nodes, metaDataList); // Starting offset of metadata long directoryOffset = writer.BaseStream.Position; // Write the number of files (4 bytes) writer.Write(metaDataList.Count); // Write all metadata foreach (var metaData in metaDataList) { // Filename (terminated with a null character) writer.Write(Encoding.ASCII.GetBytes(metaData.filename)); writer.Write((byte)0); // Null terminator at the end of the filename // File offset (4 bytes) writer.Write((int)metaData.offset); // File size (4 bytes) writer.Write((int)metaData.size); } // Finally, write the directory offset (4 bytes) writer.Write((int)directoryOffset); } // Recursive function to write file and directory contents private void WriteContent(BinaryWriter writer, TreeNodeCollection nodes, List<(string filename, long offset, int size)> metaDataList) { foreach (TreeNode node in nodes) { string fullPath = node.Tag.ToString(); if (Directory.Exists(fullPath)) // Directory handling { // Recursive call for files and subdirectories within the directory WriteContent(writer, node.Nodes, metaDataList); } else if (File.Exists(fullPath)) // File handling { FileInfo fileInfo = new FileInfo(fullPath); // Write file content to the archive long currentOffset = writer.BaseStream.Position; using (FileStream fs = new FileStream(fullPath, FileMode.Open)) { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0) { writer.Write(buffer, 0, bytesRead); } } // Add file metadata to the list metaDataList.Add((node.FullPath, currentOffset, (int)fileInfo.Length)); } } } So the only problem I have is the folder (Node) - subfolder (childnode) issue. Edited October 7, 20241 yr by Krisztian1990 code updated, but fix needed
October 10, 20241 yr Author Localization Hi again! Sry for the comment, I managed to fix all the issues. Sry for the question.
Create an account or sign in to comment