Newer
Older
Epoc / zPakr / Program.cs
@Ivan Dominguez Ivan Dominguez on 13 Feb 3 KB Initial upload
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();
}