Posted 11 years ago
·
Author
This is a method for extracting the developer cid out of a chkn file. I do not know what this could be used for yet but I accidentally made it while trying to modify the contents of a chkn.
This method works on the following logic:
Step 1: Open chkn file as an archive
Step 2: Search for the index file inside the archive
Step 3: Load contents of index file to string
Step 4: Look for the developer cid line
Step 5: extract cid from line
Step 6: return it to the user
This method requires an external library "Zipforge". You can download it here: http://www.componentace.com/.NET_zip_co ... pforge.htm
assemblies:
Example usage:
I am sure there some more efficient ways of doing this. I welcome all code improvements or ideas.
This method works on the following logic:
Step 1: Open chkn file as an archive
Step 2: Search for the index file inside the archive
Step 3: Load contents of index file to string
Step 4: Look for the developer cid line
Step 5: extract cid from line
Step 6: return it to the user
This method requires an external library "Zipforge". You can download it here: http://www.componentace.com/.NET_zip_co ... pforge.htm
assemblies:
using System.IO;
using ComponentAce.Compression.ZipForge;
using ComponentAce.Compression.Archiver;
private void getDev_CID(string file)
{
ZipForge archiver = new ZipForge();
archiver.FileName = file;
archiver.OpenArchive(FileMode.Open);
ArchiveItem archiveItem = new ArchiveItem();
string start = "<developer_id>", end = "</developer_id>";
string cid = null;
string temp_index;
archiver.BeginUpdate();
if (archiver.FindFirst("index.xml", ref archiveItem))
{
archiver.EndUpdate();
archiver.ExtractToString("index.xml", out temp_index);
if (temp_index.Contains(start) && temp_index.Contains(end))
{
int Pos1 = temp_index.IndexOf(start) + start.Length;
int Pos2 = temp_index.IndexOf(end);
cid = temp_index.Substring(Pos1, Pos2 - Pos1);
if (!String.IsNullOrEmpty(cid))
{
MessageBox.Show(cid, "Cid Found", MessageBoxButtons.OK, MessageBoxIcon.None);
}
else
{
MessageBox.Show("CID is empty!", "No CID", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Index doesn't contain dev cid!", "No CID", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("No Index file found!", "No Index", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
archiver.CloseArchive();
}
Example usage:
private void button2_Click(object sender, EventArgs e)
{
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
openFileDialog1.DefaultExt = "chkn";
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Text Files (*.chkn)|*.chkn|All Files (*.*)|*.*";
openFileDialog1.Multiselect = false;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
getDev_CID(openFileDialog1.FileName);
}
}
I am sure there some more efficient ways of doing this. I welcome all code improvements or ideas.