[Release] C# Pk2 Reader (Including sourcecode)

03/10/2013 19:38 torstmn#1
Hey guys,
today I want to release my Pk2Reader to you.
It's based on "bloodman"'s original class.

I Added alot of methods/functions to it and cleaned it up totaly.

[Features]
- Read .pk2 files with any Blowfish key
- Extract file(s) out of it
- Work around with .pk2 files

[Bugs]
- Nothing found (yet)

[Available Functions/Methods]
-
Quote:
- ExtractFile(File File, string OutputPath) (+1 overflow)
Extract any file out of the .pk2 and save it to HDD
Quote:
- GetFileExtension(File File) --> string (+1 overflow)
Return the file extension of any file located inside the .pk2 (e.g ".txt")
Quote:
- GetRootFiles() --> List<File>
Returns a list of all files within the root folder
Quote:
- GetRootFolders() --> List<Folder>
Returns a list of all folders within the root folder
Quote:
- GetFiles(string ParentFolder) --> List<File>
Returns a list of all files within a specific folder
Quote:
- GetSubFolders(string ParentFolder) --> List<Folder>
Returns a list of all folders within a specific folder
Quote:
- FileExists(string Name) --> Boolean
Returns if the file you've been searching for exsist inside the .pk2
Quote:
- GetFileBytes(string Name) --> Byte[] (+1 overflow)
Returns the requested file as Byte[]
Quote:
- GetFileText(string Name) --> string (+1 overflow)
Returns the file text (e.g in itemdata_XY.txt)
Quote:
- GetFileStream(string Name) --> System.IO.Stream (+1 overflow)
Returns the stream of a file (e.g Image.FromStream(this_function))
Quote:
- GetFileNames() --> List<string>
Returns a list with all filenames
Download:
Compiled (.dll)
[Only registered and activated users can see links. Click Here To Register...]
Source (.zip)
[Only registered and activated users can see links. Click Here To Register...]
Example (.zip)
[Only registered and activated users can see links. Click Here To Register...]
Mini.pk2 (used in example)
[Only registered and activated users can see links. Click Here To Register...]
(Blowfishkey = "test")


Conclusion:
I hope it helps you to create your own .pk2 extractor. Feel free to add your own stuff and post it into this thread. Also feel free to add me to your skype contacts: MrLordschaft.
Thanks for reading.

PS: If you know how to code a writer, please tell me.
03/10/2013 20:09 3DProgrammer#2
Thanks for the release, but i already know how to do that (though more functions than i know)
If you knew how write tell me xD

#Edit : ExtractFile, It writes the data and never close the writer ^^
03/10/2013 21:40 intercsaki#3
Awesome, let's snap our jaws on another small bit of C# code! :)

Currently examining it. :3
03/11/2013 00:46 theonly112#4
Nice to see that someone did something with my code. :)
You should try importing files as well. That should be a bit more of a challenge. ;)
03/11/2013 02:23 鳳凰城#5
Going to test / review the results.

Result as your code: [Only registered and activated users can see links. Click Here To Register...]
And , where's the extract point? It only reads right?
I may work a lil bit on it but as a form * I hate consoles * and , I will post my final modified version.
03/11/2013 08:49 torstmn#6
@phoenix1337:
The example is just an example. You can also work with a GUI instead of a console.

For extracting a file:
<Instance of Reader>.ExtractFile(File file, string OutputPath)

UPDATE:
- Fixed "ExtractFile()" - Writer now closes... (thx for the report)

Download (.dll)
[Only registered and activated users can see links. Click Here To Register...]

Download source (.zip)
[Only registered and activated users can see links. Click Here To Register...]
03/11/2013 13:31 鳳凰城#7
Why do you use it in dll format? + Every command in your console , it closes the console automatically .
03/11/2013 14:38 intercsaki#8
Well, dll can be easily imported and used in applications. But one can use the source included, just bother to copy everything. :D Pros and cons at both side.
03/11/2013 20:02 LastThief*#9
Quote:
Originally Posted by Phoenix 1337 View Post
Why do you use it in dll format? + Every command in your console , it closes the console automatically .
Console.ReadLine();
03/11/2013 20:42 lesderid#10
Quote:
Originally Posted by LastThief* View Post
Console.ReadLine();
Code:
System.Console.ReadKey(true);
imo
03/12/2013 23:46 spartai333#11
Quote:
Originally Posted by intercsaki View Post
Well, dll can be easily imported and used in applications. But one can use the source included, just bother to copy everything. :D Pros and cons at both side.
.Net DLLs source code are easy to recover. Just use ILSpy or something like that. And about copying everything... Once you have a great solution for a problem, you are noob if u dont use that... Also you shouldnt use .Net or some classes in C#... You can write them from yourself ;)
03/13/2013 10:23 LastThief*#12
Quote:
Originally Posted by spartai333 View Post
.Net DLLs source code are easy to recover. Just use ILSpy or something like that. And about copying everything... Once you have a great solution for a problem, you are noob if u dont use that... Also you shouldnt use .Net or some classes in C#... You can write them from yourself ;)
Dude ... ?
03/13/2013 18:03 鳳凰城#13
Quote:
Originally Posted by spartai333 View Post
.Net DLLs source code are easy to recover. Just use ILSpy or something like that. And about copying everything... Once you have a great solution for a problem, you are noob if u dont use that... Also you shouldnt use .Net or some classes in C#... You can write them from yourself ;)
A noob , as you've said , at least he's helping people . Unless your worthless comment which creating a false point 100%. If he's a noob , we should teach him how to manage these shits , To become a pro.
03/13/2013 19:54 detCode#14
lets make pk2 writer

simple writer fonction

public void WriteFile(string Source, string InputPath)
{
//gösterilen dosyayı oku
System.IO.FileStream str = new System.IO.FileStream(Source, System.IO.FileMode.Open);
System.IO.BinaryReader readbnr = new System.IO.BinaryReader(str);
Byte[] data = readbnr.ReadBytes((int)str.Length);
str.Close();

//yaz
System.IO.BinaryWriter wrt = new System.IO.BinaryWriter(m_FileStream);
File file = m_Files.Find(item => item.Name.ToLower() == Source.ToLower());
wrt.BaseStream.Position = file.Position;
wrt.Write(data);
wrt.Close();
}

How to use
first extract config.txt in mini.pk2
change config.txt
pk2Reader.ExtractFile("config.ini", "config.ini");
...

Problems..
Its works but you cant write extra byte from old data lenght
03/14/2013 12:40 intercsaki#15
Quote:
Originally Posted by LastThief* View Post
Dude ... ?
Quote:
Originally Posted by Phoenix 1337 View Post
A noob , as you've said , at least he's helping people . Unless your worthless comment which creating a false point 100%. If he's a noob , we should teach him how to manage these shits , To become a pro.
In my opinion, the main pont was this:
Quote:
Originally Posted by spartai333 View Post
And about copying everything... Once you have a great solution for a problem, you are noob if u dont use that...
Just sayin'.