Beispiel #1
0
        public CachedFile(CompressedCache cache, Md5Hash md5, long uncompressedSize)
        {
            Cache            = cache;
            Md5              = md5;
            UncompressedSize = uncompressedSize;

            Accesses = 0;
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            server = new PipeServer("PPEX");

#if DEBUG
            LogFiles = true;
#endif

            TrimTimer = new Timer(TurboMode ? 10000 : 5000);

            if (args.Length > 0 &&
                Directory.Exists(args[0]))
            {
                PPXLocation = args[0];
            }

            PPXLocation = PPXLocation.Replace("\\\\", "\\");

            if (args.Length > 0 &&
                args.Any(x => x.ToLower() == "-nowindow"))
            {
                ShowWindow(GetConsoleWindow(), SW_HIDE);
            }

            //Attach the handler to the server
            server.OnRequest    += Server_OnRequest;
            server.OnDisconnect += Server_OnDisconnect;

            if (!Directory.Exists(PPXLocation))
            {
                Console.WriteLine("Invalid load directory! (" + PPXLocation + ")");
                return;
            }

            Console.WriteLine("Loading from " + PPXLocation);

            List <ExtendedArchive> ArchivesToLoad = new List <ExtendedArchive>();

            //Index all .ppx files in the location
            foreach (string arc in Directory.EnumerateFiles(PPXLocation, "*.ppx", SearchOption.TopDirectoryOnly)
                     .OrderBy(x => x))
            {
                var archive = new ExtendedArchive(arc);

                ArchivesToLoad.Add(archive);
            }

            const long cacheSize = (long)(1.8 * 1024 * 1024 * 1024);
            const long trimSize  = (long)(cacheSize * 0.9);

            Cache = new CompressedCache(ArchivesToLoad, new Progress <string>(Console.WriteLine), cacheSize);

            TrimTimer.Elapsed += (s, e) =>
            {
                Cache.Trim(trimSize);
                Console.WriteLine("Cache size:" + Utility.GetBytesReadable(Cache.AllocatedMemorySize));
            };

            TrimTimer.Start();

            Console.WriteLine("Finished loading " + Cache.LoadedArchives.Count + " archive(s)");

            if (Preloading)
            {
                Console.WriteLine("Preloading files...");

                foreach (var chunk in Cache.ReferenceMd5Sums.Keys.Where(x => x.File.EndsWith(".lst")).Select(x => Cache.LoadedFileReferences[x]).Distinct())
                {
                    chunk.Allocate();
                }

                //foreach (var chunk in Cache.LoadedFiles.Where(x => x.Key.Archive.StartsWith("jg2p06")).Select(x => x.Value.Chunk).Distinct())
                //    chunk.Allocate();

                foreach (var chunk in Cache.ReferenceMd5Sums.Keys.Where(x => x.File.EndsWith(".bmp")).Select(x => Cache.LoadedFileReferences[x]).Distinct())
                {
                    chunk.Allocate();
                }

                foreach (var chunk in Cache.ReferenceMd5Sums.Keys.Where(x => x.File.EndsWith(".tga")).Select(x => Cache.LoadedFileReferences[x]).Distinct())
                {
                    chunk.Allocate();
                }

                //foreach (var chunk in Cache.LoadedFiles.Where(x => x.Key.Archive.StartsWith("jg2p07")).Select(x => x.Value.Chunk).Distinct())
                //    chunk.Allocate();

                Console.WriteLine("Preloading complete.");
            }

            Cache.Trim(TrimMethod.GCCompactOnly);

            IsLoaded = true;

            string line;

            //Handle arguments from the user
            while (true)
            {
                line = Console.ReadLine();

                string[] arguments = line.Split(' ');

                switch (arguments[0])
                {
                case "exit":
                    Environment.Exit(0);
                    return;

                case "log":
                    LogFiles = !LogFiles;
                    break;

                case "turbo":
                    TurboMode = !TurboMode;
                    break;

                case "size":
                    Console.WriteLine(Utility.GetBytesReadable(Cache.AllocatedMemorySize));
                    Console.WriteLine(Cache.LoadedFiles.Count + " files allocated");
                    break;

                case "trim":
                    Cache.Trim((long)(float.Parse(arguments[1]) * 1024 * 1024));
                    break;
                }
            }
        }
Beispiel #3
0
 public CachedChunk(ExtendedArchiveChunk baseChunk, CompressedCache cache)
 {
     BaseChunk = baseChunk;
     BaseCache = cache;
 }