Beispiel #1
0
        //----------------------------------------------------------------------------------------
        public static void unpackFile(Stream as_in, string as_pathname, int mode)
        {
            global = cGlobal.INSTANCE;
            List<cGlobal.st_index> index = new List<cGlobal.st_index>();
            byte[] b_file;
            string s_ext;
            int size;

            try
            {
                index = readIndex(as_in, mode);

                for (int i = 0; i < index.Count; i++)
                {
                    if (i == index.Count - 1)
                        size = (int)(as_in.Length - index[i].pos);
                    else
                        size = (int)(index[i + 1].pos - index[i].pos);

                    b_file = new byte[size];

                    string s_name = string.Format("{0:0000}", index[i].id);

                    s_ext = global.getTypeOfFile(as_in, (int)index[i].pos, size);

                    as_in.Seek(index[i].pos, SeekOrigin.Begin);

                    using (MemoryStream ms_file = new MemoryStream())
                    {
                        ms_file.CopyFrom(as_in, size);
                        ms_file.Position = 0;

                        if (global.RECURSIVE)
                            global.processFile(ms_file, as_pathname, s_name, as_pathname + s_name + s_ext);
                        else
                            global.writeFileToDisk(ms_file, as_pathname + s_name + s_ext);
                    }

                    b_file = null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            global = cGlobal.INSTANCE;
            bool result = false;

            ConsoleTraceListener ctl_trace = new ConsoleTraceListener();
            Trace.Listeners.Add(ctl_trace);

            global.ts_TypeTrace.Level = TraceLevel.Error;
            sw_watch = new Stopwatch();

            try
            {
                global.readArguments(args);

                Trace.AutoFlush = true;

                sw_watch.Start();

                switch (global.ACTION)
                {
                    case "COMP":
                        if (global.SOURCE == "")
                            throw new ToDException("The option -i is missing !");
                        if (global.DESTINATION == "")
                            throw new ToDException("The option -o is missing !");
                        if (global.MODE == -1)
                            throw new ToDException("The option -m is missing !");
                        using (FileStream fs_in = new FileStream(global.SOURCE, FileMode.Open))
                        using (MemoryStream ms_out = new MemoryStream())
                        {
                            Compression.compFile(fs_in, ms_out);

                            global.writeFileToDisk(ms_out, global.DESTINATION);
                        }
                        break;

                    case "DECOMP":
                        if (global.SOURCE == "")
                            throw new ToDException("The option -i is missing !");
                        if (global.DESTINATION == "")
                            throw new ToDException("The option -o is missing !");
                        result = false;
                        using (FileStream fs_in = new FileStream(global.SOURCE, FileMode.Open))
                        using (MemoryStream ms_out = new MemoryStream())
                        {
                            Compression.decompFile(fs_in, ms_out);

                            if (global.RECURSIVE)
                                result = global.processFile(ms_out, global.DESTINATION, "", global.DESTINATION);
                        }
                        break;

                    case "EXTRACT":
                        if (global.SOURCE == "")
                            throw new ToDException("The option -i is missing !");
                        if (global.DIR_OUT == "")
                            throw new ToDException("The option -d is missing !");
                        extractFromIso();
                        break;

                    case "INSERT":
                        if (global.SOURCE == "")
                            throw new ToDException("The option -i is missing !");
                        if (global.DESTINATION == "")
                            throw new ToDException("The option -o is missing !");
                        insertToIso();
                        break;

                    case "PACK":
                        if (global.SOURCE == "")
                            throw new ToDException("The option -i is missing !");
                        if (global.DESTINATION == "")
                            throw new ToDException("The option -o is missing !");
                        if (global.MODE == -1)
                            throw new ToDException("The option -m is missing !");
                        Archive.packFile();
                        break;

                    case "UNPACK":
                        if (global.SOURCE == "")
                            throw new ToDException("The option -i is missing !");
                        using (FileStream fs_in = new FileStream(global.SOURCE, FileMode.Open))
                        {
                            Archive.unpackFile(fs_in, global.DIR_OUT, 1);
                        }
                        break;

                    default:
                        throw new ToDException(string.Format("Unknow action {0} !", global.ACTION));
                }
            }
            catch (ToDException ex)
            {
                Trace.WriteLine(ex.Message + Environment.NewLine, "ERROR");
                usage();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message + Environment.NewLine, "ERROR");
                Trace.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw_watch.Stop();
                Trace.WriteLineIf(global.ts_TypeTrace.TraceVerbose, string.Format("Terminated. Execution time : {0}", sw_watch.Elapsed));
            }
        }
Beispiel #3
0
        public static void unpackBDat(MemoryStream ams_file, List<cGlobal.st_index> al_index, string as_path)
        {
            global = cGlobal.INSTANCE;
            byte[] b_file;
            string s_ext;

            Trace.Indent();

            try
            {
                foreach (cGlobal.st_index file in al_index)
                {
                    b_file = new byte[file.size];

                    string s_name = string.Format("{0:0000}", file.id);

                    s_ext = global.getTypeOfFile(ams_file, (int)file.pos, (int)file.size);

                    using (MemoryStream ms_file = new MemoryStream())
                    {
                        ams_file.CopyTo(ms_file, file.size, file.pos);
                        ms_file.Position = 0;

                        if (global.RECURSIVE)
                            global.processFile(ms_file, as_path, s_name, as_path + s_name + s_ext);
                        else
                            global.writeFileToDisk(ms_file, as_path + s_name + s_ext);
                    }

                    b_file = null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Trace.Unindent();
            }
        }