Example #1
0
 public AssetStreamWriter(Stream output, GameModuleTree modules, GameAssetStorage storage)
     : base(output)
 {
     Modules = modules;
     Storage = storage ?? (GameAssetStorage)modules.Root.FindChildByClassID(ClassIDAttribute.GetClassID(typeof(GameAssetStorage)));
 }
Example #2
0
        static void Run()
        {
            Trace.WriteLine("================================");
            Trace.WriteLine("Halak Bibim Asset Server");
            Trace.WriteLine("================================");
            Trace.WriteLine(string.Format("Listen Port: {0}", NetworkAssetProvider.DefaultPort));

            var modules      = new GameModuleTree();
            var assetStorage = new GameAssetStorage();
            var assetKitchen = new GameAssetKitchen(assetStorage);
            var assetServer  = new NetworkGameAssetServer(assetKitchen);

            modules.Root.AttachChild(assetStorage);
            modules.Root.AttachChild(assetKitchen);
            modules.Root.AttachChild(assetServer);

            bool closed = false;

            while (closed == false)
            {
                string command;
                if (ConsoleWindow.CommandQueue.TryDequeue(out command))
                {
                    switch (command.ToLower())
                    {
                    case "exit":
                        closed = true;
                        break;
                    }

                    if (command.StartsWith("deletecache "))
                    {
                        int    numberOfDeletedFiles = 0;
                        string path = command.Substring("deletecache ".Length).Trim();
                        try
                        {
                            string[] files = Directory.GetFiles(path, "*." + GameAsset.BinaryFileExtension, SearchOption.AllDirectories);
                            foreach (string item in files)
                            {
                                try
                                {
                                    File.Delete(item);
                                    numberOfDeletedFiles++;
                                }
                                catch (Exception ex)
                                {
                                    Trace.WriteLine(ex);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex);
                        }

                        Trace.TraceInformation("Asset cache deleted ({0}).", numberOfDeletedFiles);
                    }

                    if (command.StartsWith("precook "))
                    {
                        int index1 = "precook ".Length;
                        int index2 = command.IndexOf(">>", index1);
                        if (index2 == -1)
                        {
                            Precook(assetServer, command.Substring(index1).Trim());
                        }
                        else
                        {
                            Precook(assetServer,
                                    command.Substring(index1, index2 - index1).Trim(),
                                    command.Substring(index2 + ">>".Length).Trim());
                        }
                    }

                    if (command.StartsWith("compress "))
                    {
                        int index1 = "compress ".Length;
                        int index2 = command.IndexOf(">>", index1);

                        string directory   = command.Substring(index1, index2 - index1).Trim();
                        string zipFilePath = Path.ChangeExtension(command.Substring(index2 + ">>".Length), "zip").Trim();
                        Compress(directory, zipFilePath);
                    }


                    if (command.StartsWith("precook_and_compress "))
                    {
                        int index1 = "precook_and_compress ".Length;
                        int index2 = command.IndexOf(">>", index1);

                        string directory   = command.Substring(index1, index2 - index1).Trim();
                        string zipFilePath = Path.ChangeExtension(command.Substring(index2 + ">>".Length), "zip").Trim();
                        Precook(assetServer, directory);
                        Compress(directory, zipFilePath);
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(10);
                }
            }

            assetServer.Alive = false;
            Trace.TraceInformation("AssetServer closed.");
        }
Example #3
0
 public AssetStreamWriter(Stream output, GameModuleTree modules)
     : this(output, modules, null)
 {
 }