コード例 #1
0
ファイル: CASContainer.cs プロジェクト: roblankey/CASCHost
        public static void OpenEncoding()
        {
            Logger.LogInformation("Loading Encoding...");

            string key  = BuildConfig.GetKey("encoding").ToString();
            var    path = Path.Combine(Settings.SystemFilesPath, key);

            LocalIndexEntry idxInfo = LocalIndexHandler?.GetIndexInfo(BuildConfig.GetKey("encoding"));

            if (idxInfo != null)
            {
                path            = Path.Combine(BasePath, "Data", "data", string.Format("data.{0:D3}", idxInfo.Archive));
                EncodingHandler = new EncodingHandler(DataHandler.Read(path, idxInfo));
            }
            else
            {
                path = Helper.FixOutputPath(path, "data");

                if (!File.Exists(path))
                {
                    string url = "/data/" + key.Substring(0, 2) + "/" + key.Substring(2, 2) + "/" + key;
                    if (!DataHandler.Download(url, path))
                    {
                        Logger.LogCritical($"Unable to download Encoding {key}.");
                    }
                }

                EncodingHandler = new EncodingHandler(DataHandler.ReadDirect(path));
            }
        }
コード例 #2
0
        public IActionResult Encoding(Guid guid)
        {
            if (guid == Guid.Empty)
            {
                return(Problem("Empty GUID is invalid."));
            }

            _logger.LogInformation("Enter EncodingCheck.");

            //database process id
            Guid processId = Guid.NewGuid();

            try
            {
                //data map id
                Task.Run(() =>
                {
                    using (EncodingHandler handler = new EncodingHandler(_settings, _eventHub, _preingestCollection))
                    {
                        handler.Logger = _logger;
                        handler.SetSessionGuid(guid);
                        processId = handler.AddProcessAction(processId, typeof(EncodingHandler).Name, String.Format("Retrieve the encoding for all metadata files : folder {0}", guid), String.Concat(typeof(EncodingHandler).Name, ".json"));
                        _logger.LogInformation("Execute handler ({0}) with GUID {1}.", typeof(EncodingHandler).Name, guid.ToString());
                        handler.Execute();
                    }
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An exception was thrown in {0}: '{1}'.", typeof(EncodingHandler).Name, e.Message);
                return(ValidationProblem(e.Message, typeof(EncodingHandler).Name));
            }
            _logger.LogInformation("Exit EncodingCheck.");
            return(new JsonResult(new { Message = String.Format("Encoding UTF-8 .metadata files check is started."), SessionId = guid, ActionId = processId }));
        }
コード例 #3
0
ファイル: CASContainer.cs プロジェクト: roblankey/CASCHost
        public static void Close()
        {
            RootHandler?.NewFiles.Clear();

            Settings = null;

            BuildInfo   = null;
            Versions    = null;
            CDNs        = null;
            BuildConfig = null;
            CDNConfig   = null;

            LocalIndexHandler = null;
            CDNIndexHandler   = null;
            DownloadHandler   = null;
            InstallHandler    = null;

            EncodingHandler?.Dispose();
            RootHandler?.Dispose();

            // force GC
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
コード例 #4
0
ファイル: ClientHandler.cs プロジェクト: HeroesReplay/TACTLib
        public ClientHandler(string basePath, ClientCreateArgs createArgs)
        {
            basePath   = basePath ?? "";
            BasePath   = basePath;
            CreateArgs = createArgs;
            string flavorInfoProductCode = null;

            if (createArgs.UseContainer && !Directory.Exists(basePath))
            {
                throw new FileNotFoundException("invalid archive directory");
            }

            var dbPath = Path.Combine(basePath, createArgs.ProductDatabaseFilename);

            try {
                if (File.Exists(dbPath))
                {
                    using (var _ = new PerfCounter("AgentDatabase::ctor`string`bool"))
                        foreach (var install in new AgentDatabase(dbPath).Data.ProductInstall)
                        {
                            if (string.IsNullOrEmpty(createArgs.Flavor) || install.Settings.GameSubfolder.Contains(createArgs.Flavor))
                            {
                                AgentProduct = install;
                                break;
                            }
                        }

                    if (AgentProduct == null)
                    {
                        throw new InvalidDataException();
                    }

                    Product = ProductHelpers.ProductFromUID(AgentProduct.ProductCode);
                }
                else
                {
                    throw new InvalidDataException();
                }
            } catch {
                try {
                    if (File.Exists(Path.Combine(basePath, ".flavor.info")))
                    {
                        // mixed installation, store the product code to be used below
                        flavorInfoProductCode = File.ReadLines(Path.Combine(basePath, ".flavor.info")).Skip(1).First();
                        Product  = ProductHelpers.ProductFromUID(flavorInfoProductCode);
                        BasePath = basePath = Path.Combine(basePath, "../"); // lmao

                        Logger.Info("Core", $".flavor.info detected. Found product \"{flavorInfoProductCode}\"");
                    }
                    else
                    {
                        throw new InvalidDataException();
                    }
                } catch {
                    try {
                        Product = ProductHelpers.ProductFromLocalInstall(basePath);
                    } catch {
                        if (createArgs.VersionSource == ClientCreateArgs.InstallMode.Local)    // if we need an archive then we should be able to detect the product
                        {
                            throw;
                        }

                        Product = createArgs.OnlineProduct;
                    }
                }

                AgentProduct = new ProductInstall {
                    ProductCode = flavorInfoProductCode ?? createArgs.Product ?? ProductHelpers.UIDFromProduct(Product),
                    Settings    = new UserSettings {
                        SelectedTextLanguage   = createArgs.TextLanguage ?? "enUS",
                        SelectedSpeechLanguage = createArgs.SpeechLanguage ?? "enUS",
                        PlayRegion             = "us"
                    }
                };

                if (AgentProduct.Settings.SelectedSpeechLanguage == AgentProduct.Settings.SelectedTextLanguage)
                {
                    AgentProduct.Settings.Languages.Add(new LanguageSetting {
                        Language = AgentProduct.Settings.SelectedTextLanguage,
                        Option   = LanguageOption.LangoptionTextAndSpeech
                    });
                }
                else
                {
                    AgentProduct.Settings.Languages.Add(new LanguageSetting {
                        Language = AgentProduct.Settings.SelectedTextLanguage,
                        Option   = LanguageOption.LangoptionText
                    });

                    AgentProduct.Settings.Languages.Add(new LanguageSetting {
                        Language = AgentProduct.Settings.SelectedSpeechLanguage,
                        Option   = LanguageOption.LangoptionSpeech
                    });
                }
            }

            if (string.IsNullOrWhiteSpace(createArgs.TextLanguage))
            {
                createArgs.TextLanguage = AgentProduct.Settings.SelectedTextLanguage;
            }

            if (string.IsNullOrWhiteSpace(createArgs.SpeechLanguage))
            {
                createArgs.SpeechLanguage = AgentProduct.Settings.SelectedSpeechLanguage;
            }

            if (createArgs.Online)
            {
                using var _ = new PerfCounter("INetworkHandler::ctor`ClientHandler");
                if (createArgs.OnlineRootHost.StartsWith("ribbit:"))
                {
                    NetHandle = new RibbitCDNClient(this);
                }
                else
                {
                    NetHandle = new NGDPClient(this);
                }
            }

            if (createArgs.VersionSource == ClientCreateArgs.InstallMode.Local)
            {
                var installationInfoPath = Path.Combine(basePath, createArgs.InstallInfoFileName) + createArgs.ExtraFileEnding;
                if (!File.Exists(installationInfoPath))
                {
                    throw new FileNotFoundException(installationInfoPath);
                }

                using var _      = new PerfCounter("InstallationInfo::ctor`string");
                InstallationInfo = new InstallationInfo(installationInfoPath, AgentProduct.ProductCode);
            }
            else
            {
                using var _      = new PerfCounter("InstallationInfo::ctor`INetworkHandler");
                InstallationInfo = new InstallationInfo(NetHandle, createArgs.OnlineRegion);
            }

            Logger.Info("CASC", $"{Product} build {InstallationInfo.Values["Version"]}");

            if (createArgs.UseContainer)
            {
                Logger.Info("CASC", "Initializing...");
                using var _      = new PerfCounter("ContainerHandler::ctor`ClientHandler");
                ContainerHandler = new ContainerHandler(this);
            }

            using (var _ = new PerfCounter("ConfigHandler::ctor`ClientHandler"))
                ConfigHandler = new ConfigHandler(this);

            using (var _ = new PerfCounter("EncodingHandler::ctor`ClientHandler"))
                EncodingHandler = new EncodingHandler(this);

            if (ConfigHandler.BuildConfig.VFSRoot != null)
            {
                using var _ = new PerfCounter("VFSFileTree::ctor`ClientHandler");
                VFS         = new VFSFileTree(this);
            }

            if (createArgs.Online)
            {
                m_cdnIdx = CDNIndexHandler.Initialize(this);
            }

            using (var _ = new PerfCounter("ProductHandlerFactory::GetHandler`TACTProduct`ClientHandler`Stream"))
                ProductHandler = ProductHandlerFactory.GetHandler(Product, this, OpenCKey(ConfigHandler.BuildConfig.Root.ContentKey));

            Logger.Info("CASC", "Ready");
        }
コード例 #5
0
ファイル: CASContainer.cs プロジェクト: roblankey/CASCHost
        public static void Save()
        {
            Settings.Cache?.Clean();

            //Patch exe
            //Patcher.Run("http://" + CASContainer.Settings.Host);

            // Entries
            var entries = SaveEntries().Result;

            // CDN Archives
            Settings.Logger.LogInformation("Starting CDN Index.");
            CDNIndexHandler?.CreateArchive(entries);

            // Root
            Settings.Logger.LogInformation("Starting Root.");
            foreach (var entry in entries)
            {
                RootHandler.AddEntry(entry.Path, entry);
            }
            entries.Add(RootHandler.Write());             //Add to entry list

            // Download
            if (DownloadHandler != null)
            {
                Settings.Logger.LogInformation("Starting Download.");

                foreach (var entry in entries)
                {
                    DownloadHandler.AddEntry(entry);
                }
                entries.Add(DownloadHandler.Write());                 //Add to entry list
            }

            if (InstallHandler != null)
            {
                Settings.Logger.LogInformation("Starting Install.");
                var installManifest = InstallHandler.Write(entries);

                if (installManifest != null)
                {
                    entries.Add(installManifest);                     //Add to entry list
                }
            }

            // Encoding
            Settings.Logger.LogInformation("Starting Encoding.");
            foreach (var entry in entries)
            {
                EncodingHandler.AddEntry(entry);
            }
            entries.Insert(0, EncodingHandler.Write());


            Settings.Logger.LogInformation("Starting Configs.");

            // CDN Config
            CDNConfig.Remove("archive-group");
            CDNConfig.Remove("patch-archives");
            CDNConfig.Remove("patch-archive-group");

            // Build Config
            BuildConfig.Set("patch", "");
            BuildConfig.Set("patch-size", "0");
            BuildConfig.Set("patch-config", "");

            string buildconfig = BuildConfig.Write();
            string cdnconfig   = CDNConfig.Write();
            string version     = BuildInfo["Version"];

            // Build Info - redundant
            BuildInfo["Build Key"] = buildconfig;
            BuildInfo["CDN Key"]   = cdnconfig;
            BuildInfo["CDN Hosts"] = string.Join(" ", Settings.CDNs);
            BuildInfo.Write();

            // CDNs file
            CDNs["Hosts"] = string.Join(" ", Settings.CDNs);
            CDNs.Write();

            // Versions file
            Versions["BuildConfig"]  = buildconfig;
            Versions["CDNConfig"]    = cdnconfig;
            Versions["VersionsName"] = version;
            Versions["BuildId"]      = version.Split('.').Last();
            Versions.Write();

            // Done!
            Logger.LogInformation("CDN Config: " + cdnconfig);
            Logger.LogInformation("Build Config: " + buildconfig);

            // update Cache files
            Settings.Cache?.Save();

            // cleanup
            entries.Clear();
            entries.TrimExcess();
            Close();
        }
コード例 #6
0
        private CASCHandler(CASCConfig config, ProgressReportSlave worker)
        {
            Config = config;

            if (!config.OnlineMode)
            {
                Debugger.Log(0, "CASC", "CASCHandler: loading local indices\r\n");

                using (PerfCounter _ = new PerfCounter("LocalIndexHandler.Initialize()")) {
                    LocalIndex = LocalIndexHandler.Initialize(config, worker);
                }

                Debugger.Log(0, "CASC", $"CASCHandler: loaded {LocalIndex.Count} local indices\r\n");
            }
            else      // todo: supposed to do this?
            {
                Debugger.Log(0, "CASC", "CASCHandler: loading CDN indices\r\n");

                using (PerfCounter _ = new PerfCounter("CDNIndexHandler.Initialize()")) {
                    CDNIndex = CDNIndexHandler.Initialize(config, worker, Cache);
                }

                Debugger.Log(0, "CASC", $"CASCHandler: loaded {CDNIndex.Count} CDN indexes\r\n");
            }

            Debugger.Log(0, "CASC", "CASCHandler: loading encoding entries\r\n");
            using (PerfCounter _ = new PerfCounter("new EncodingHandler()")) {
                using (BinaryReader encodingReader = OpenEncodingKeyFile()) {
                    EncodingHandler = new EncodingHandler(encodingReader, worker);
                }
            }
            Debugger.Log(0, "CASC", $"CASCHandler: loaded {EncodingHandler.Count} encoding entries\r\n");

            Debugger.Log(0, "CASC", "CASCHandler: loading root data\r\n");
            using (PerfCounter _ = new PerfCounter("new RootHandler()")) {
                using (BinaryReader rootReader = OpenRootKeyFile()) {
                    RootHandler = new RootHandler(rootReader, worker, this);
                }
            }

            //if ((CASCConfig.LoadFlags & LoadFlags.Download) != 0)
            //{
            //    Debugger.Log(0, "CASC", "CASCHandler: loading download data\r\n");
            //    using (var _ = new PerfCounter("new DownloadHandler()"))
            //    {
            //        using (BinaryReader fs = OpenDownloadFile(EncodingHandler))
            //            DownloadHandler = new DownloadHandler(fs, worker);
            //    }
            //    Debugger.Log(0, "CASC", $"CASCHandler: loaded {EncodingHandler.Count} download data\r\n");
            //}

            //if ((CASCConfig.LoadFlags & LoadFlags.Install) != 0) {
            //    Debugger.Log(0, "CASC", "CASCHandler: loading install data\r\n");
            //    using (var _ = new PerfCounter("new InstallHandler()"))
            //    {
            //        using (var fs = OpenInstallFile(EncodingHandler))
            //            InstallHandler = new InstallHandler(fs, worker);
            //        InstallHandler.Print();
            //    }
            //    Debugger.Log(0, "CASC", $"CASCHandler: loaded {InstallHandler.Count} install data\r\n");
            //}
        }