Пример #1
0
        private Archive()
        {
            myDictionaries = new Dictionary <Type, Dictionary <string, object> >();

            foreach (RManager manager in Res.Managers)
            {
                myDictionaries.Add(manager.ValueType, new Dictionary <String, Object>());
            }

            myName          = "Untitled";
            myAuthor        = "Unknown";
            myAuthorEmail   = "None given";
            myAuthorWebsite = "None given";
            myDescription   = "None given";
            myVersion       = "1.0";
            myDest          = ArchiveDest.Shared;
        }
Пример #2
0
        internal void LoadPropertiesFromInfoFile(String filePath)
        {
            String[] lines = File.ReadAllLines(filePath);
            myReferences = new string[0];

            foreach (String line in lines)
            {
                if (line.Trim().Length > 0)
                {
                    String[] split = line.Split('"');
                    String   key   = split[1].ToLower();
                    String   val   = split[3];

                    switch (key)
                    {
                    case "name":
                        myName = val; break;

                    case "author":
                        myAuthor = val; break;

                    case "author email":
                        myAuthorEmail = val; break;

                    case "author website":
                        myAuthorWebsite = val; break;

                    case "description":
                        myDescription = val; break;

                    case "version":
                        myVersion = val; break;

                    case "destination":
                        myDest = (val.ToLower() == "server" ? ArchiveDest.Server : val.ToLower() == "client" ? ArchiveDest.Client : ArchiveDest.Shared); break;

                    case "references":
                        myReferences = val.Split(','); break;
                    }
                }
            }
        }
Пример #3
0
        public static void LoadFromOrderFile(String orderFilePath, bool server = true, bool client = true)
        {
            UnloadAllArchives();

            String rootPath = orderFilePath.Substring(0, orderFilePath.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar;

            String[] lines = File.ReadAllLines(orderFilePath);
            foreach (String line in lines)
            {
                string path = line.Split(new String[] { "//" }, StringSplitOptions.None)[0].Trim();
                if (path != "")
                {
                    int         archive = LoadArchive(rootPath + path);
                    ArchiveDest dest    = GetArchiveDestination(archive);

                    if (dest == ArchiveDest.Shared ||
                        (client && dest == ArchiveDest.Client) ||
                        (server && dest == ArchiveDest.Server))
                    {
                        MountArchive(archive);
                    }
                }
            }
        }
Пример #4
0
        internal Archive(String filePath, bool unpackData = true)
            : this()
        {
            myFilePath = filePath;

            ushort archiverVersion;

            byte[] bytes;
            byte[] hash;

            using (FileStream fstr = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader bstr = new BinaryReader(fstr))
                {
                    archiverVersion = bstr.ReadUInt16();
                    myName          = bstr.ReadString();
                    myAuthor        = bstr.ReadString();
                    myVersion       = bstr.ReadString();
                    myAuthorWebsite = bstr.ReadString();
                    myAuthorEmail   = bstr.ReadString();
                    myDescription   = bstr.ReadString();
                    myDest          = (ArchiveDest)bstr.ReadByte();

                    int len = bstr.ReadInt32();
                    bytes = bstr.ReadBytes(len);
                    len   = bstr.ReadInt32();
                    hash  = bstr.ReadBytes(len);
                }
            }

            myHash = Encoding.ASCII.GetString(hash);

            if (!unpackData)
            {
                return;
            }

            byte[] data;

            using (MemoryStream mstr = new MemoryStream(bytes))
            {
                using (BZip2InputStream cstr = new BZip2InputStream(mstr))
                {
                    using (MemoryStream ostr = new MemoryStream())
                    {
                        int chunkSize = 4096;

                        byte[] buffer = new byte[chunkSize];
                        int    len;

                        while ((len = cstr.Read(buffer, 0, chunkSize)) > 0)
                        {
                            ostr.Write(buffer, 0, len);
                        }

                        ostr.Flush();

                        data = ostr.ToArray();
                    }
                }
            }

            byte[] newHash = new SHA256CryptoServiceProvider().ComputeHash(data);

            if (!Enumerable.SequenceEqual(hash, newHash))
            {
                throw new Exception("The data in archive \"" + Name + "\" has been corrupted!");
            }

            using (MemoryStream mstr = new MemoryStream(data))
            {
                using (BinaryReader bstr = new BinaryReader(mstr))
                {
                    while (mstr.Position < mstr.Length)
                    {
                        String typeName = bstr.ReadString();
                        Type   type     = Assembly.GetExecutingAssembly().GetType(typeName);

                        if (type == null)
                        {
                            foreach (Type t in myDictionaries.Keys)
                            {
                                if (typeName == t.FullName)
                                {
                                    type = t;
                                    break;
                                }
                            }
                        }

                        long pos = bstr.ReadUInt32();

                        if (type != null)
                        {
                            RManager manager = Res.GetManager(type);

                            while (mstr.Position < pos)
                            {
                                String key = bstr.ReadString();
                                object obj = manager.LoadFromArchive(bstr);
                                myDictionaries[type].Add(key, obj);
                            }
                        }

                        mstr.Seek(pos, SeekOrigin.Begin);
                    }
                }
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            if (first)
            {
                Res.RegisterManager(new MarsMiner.Client.Graphics.RTexture2DManager());
                first = false;
            }

            if (args.Length > 1)
            {
                foreach (String str in args)
                {
                    Main(new String[] { str });
                }

                return;
            }

            String directoryPath = "";

            if (args.Length > 0)
            {
                directoryPath = args[0];
            }
            else
            {
                do
                {
                    Console.WriteLine("Directory path to create archive from:");
                    directoryPath = Console.ReadLine();

                    if (!Directory.Exists(directoryPath))
                    {
                        Console.WriteLine("Directory does not exist!");
                        directoryPath = "";
                    }
                }while (directoryPath == "");
            }

            Console.WriteLine("Creating archive...");

            int archive = Res.CreateFromDirectory(directoryPath);

            ArchiveDest dest = Res.GetArchiveDestination(archive);

            Console.WriteLine((dest == ArchiveDest.Client ? "Client" : dest == ArchiveDest.Server ? "Server" : "Shared") + " archive \"" + Res.GetArchiveProperty(archive, ArchiveProperty.Name) + "\" created.");

            directoryPath = "";

            if (args.Length > 0)
            {
                directoryPath = Directory.GetCurrentDirectory() + "\\";
            }
            else
            {
                do
                {
                    Console.WriteLine("Directory path to save archive to:");
                    directoryPath = Console.ReadLine();

                    if (directoryPath.Length < 2 || directoryPath[1] != ':')
                    {
                        directoryPath = Directory.GetCurrentDirectory() + (directoryPath.StartsWith("\\") || directoryPath.StartsWith("/") ? "" : "\\") + directoryPath;
                    }

                    if (!directoryPath.EndsWith("\\") && !directoryPath.EndsWith("/"))
                    {
                        directoryPath += "\\";
                    }

                    if (!Directory.Exists(directoryPath))
                    {
                        Console.WriteLine("Directory does not exist!");
                        Console.WriteLine("Create directory \"" + directoryPath + "\"? [y/n]");

                        if (Console.ReadLine().ToLower()[0] == 'y')
                        {
                            Directory.CreateDirectory(directoryPath);
                            break;
                        }

                        directoryPath = "";
                    }
                }while (directoryPath == "");
            }

            Console.WriteLine("Compressing...");
            Res.SaveArchiveToFile(archive, directoryPath + (dest == ArchiveDest.Server ? "sv_" : dest == ArchiveDest.Client ? "cl_" : "sh_") + Res.GetArchiveProperty(archive, ArchiveProperty.Name).ToLower().Replace(" ", "") + Res.DefaultResourceExtension);

            if (args.Length == 0)
            {
                Console.WriteLine("Archive saved. Press any key to exit...");
                Console.ReadKey();
            }
        }