Newer
Older
Epoc / zPakr / Program.cs
@Ivan Dominguez Ivan Dominguez on 13 Feb 5 KB License for Epoc an zPakr
/*
# zPak and zPakr
Copyright 2025 [XWolfOverride](https://github.com/XWolfOverride)
 
## Smaol permission notice:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- Any modifications of the software will maintain the copyright notice of the previous modifiers and optionally add a new copyright notice below oredred by date.
- The above copyright notice chain and this permission notice shall be accessible by final user, on software start or in a designed screen, dialog or option dedicated to license information.
 
**THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**

*/
using XWolf.Z;

Console.WriteLine("zPakr, a zPak file handler (C) XWolfOverride 2025. [https://github.com/XWolfOverride]");
if (args.Length == 0)
    DoHelp();
else
#if !DEBUG
    try
    {
#else
{
#endif
        var cmds = new Cmds(args);
        switch (cmds.Action)
        {
            case Cmds.CmdAction.CREATE:
                DoCreate(cmds.PakFile, cmds.From);
                break;
            case Cmds.CmdAction.ADD:
                DoAdd(cmds.PakFile, cmds.From, cmds.To);
                break;
            case Cmds.CmdAction.LIST:
                DoList(cmds.PakFile);
                break;
            case Cmds.CmdAction.EXTRACT:
                DoExtract(cmds.PakFile, cmds.To);
                break;
            case Cmds.CmdAction.FILE:
                DoFile(cmds.PakFile, cmds.From, cmds.To);
                break;
            case Cmds.CmdAction.DUMP:
                DoDump(cmds.PakFile, cmds.From);
                break;
            case Cmds.CmdAction.HELP:
                DoHelp();
                break;
            default:
                throw new NotImplementedException();
        }
    }
#if !DEBUG
    catch (ArgumentException e)
    {
        Console.WriteLine($"[!! What?] {e.Message}");
        DoHelp();
    }
    catch (NotImplementedException e)
    {
        Console.WriteLine($"[!! Where?] Something is missing! {e.Message}");
    }
    catch (IOException e)
    {
        Console.WriteLine($"[!! I/O?] {e.Message}");
    }
    catch (Exception e)
    {
        Console.WriteLine($"[!! Huh?] {e.GetType().Name}:{e.Message}.");
    }
#endif

static void DoHelp()
{
    Console.WriteLine(" usage:zPakr -c -l -x -f -d -h -?");
    Console.WriteLine("  -c <pak-file> <source-folder> ...... Create pak-file from all source-folder files.");
    //Console.WriteLine("  -a <pak-file> <source-file> [<pak-path>] Adds source-file to pak-file, file name is used if no pak-path defined.");
    Console.WriteLine("  -l <pak-file> ...................... List files inside pak-file.");
    Console.WriteLine("  -x <pak-file> [<dest-folder>] ...... Extract all files from pak-file to dest-folder or current one.");
    Console.WriteLine("  -f <pak-file> <file> [<dest-path>] . Extract single file from pak-file to dest-path or orignal file name in current folder.");
    Console.WriteLine("  -d <pak-file> <file> ............... Dump contents of file in pak-file to sdtout.");
    Console.WriteLine("  -h or -? ........................... This help, default if no arguments.");
    Console.WriteLine();
    Console.WriteLine(" NOTE: Pak files maintains original folder structure, but does not record empty foldres.");
    Console.WriteLine(" NOTE: Pak files are designed to work as stub on other files, -c can use any file with no pax-file data and appends a pak-file as stub maintaining original data.");
}

static void DoCreate(string pakFile, string source)
{
    if (File.Exists(pakFile))
        File.Delete(pakFile);
    var z = new zPak(pakFile);
    //...
    z.Close();
}

static void DoAdd(string pakFile, string source, string destPath)
{
    if (string.IsNullOrWhiteSpace(destPath))
        destPath = Path.GetFileName(source);
    var z = new zPak(pakFile, false);
    //...
    z.Close();
    throw new NotImplementedException("Add command not supported right now.");
}

static void DoList(string pakFile)
{
    var z = new zPak(pakFile, false);
    //...
    z.Close();
}

static void DoExtract(string pakFile, string destFolder)
{
    if (string.IsNullOrWhiteSpace(destFolder))
        destFolder = ".";
    var z = new zPak(pakFile, false);
    //...
    z.Close();
}

static void DoFile(string pakFile, string file, string destPath)
{
    if (string.IsNullOrWhiteSpace(destPath))
        destPath = Path.GetFileName(file);
    var z = new zPak(pakFile, false);
    //...
    z.Close();
}

static void DoDump(string pakFile, string file)
{
    var z = new zPak(pakFile, false);
    //...
    z.Close();
}