public ModMetadataActor()
        {
            Receive <LoadModMetadataCommand>(command =>
            {
                bool exists = Directory.Exists(command.Path);

                if (!exists)
                {
                    // TODO : User friendly message
                }

                string modInfoXmlPath = Path.Combine(command.Path, ModInfoXml);

                var modInfoXml = XDocument.Load(modInfoXmlPath);

                var modInfo = (from name in modInfoXml.Descendants()
                               select new
                {
                    Name = name.Element("Name")?.Value,
                    Id = name.Element("Id")?.Value,
                    Version = name.Element("Version")?.Value,
                    Signature = name.Element("Signature")?.Value
                }).FirstOrDefault();

                var dataFolderPath = Path.Combine(command.Path, "data");
                var databasePath   = Path.Combine(dataFolderPath, DefaultDatabaseName);

                if (!File.Exists(databasePath))
                {
                    // TODO : User friendly message
                }

                var stringTables = Directory.GetFiles(dataFolderPath, "*.gst");

                if (!stringTables.Any())
                {
                    // TODO : User friendly message
                }

                var builder = ImmutableDictionary.CreateBuilder <string, StringTableMetadata>();

                foreach (var stringTable in stringTables)
                {
                    string lang       = stringTable.Split('.')[1];
                    var tableMetadata = new StringTableMetadata(lang, stringTable);

                    builder.Add(lang, tableMetadata);
                }

                var stringTableMetadata = builder.ToImmutable();

                var modMetadata = new ModMetadata(modInfo.Id, modInfo.Name, modInfo.Version, modInfo.Signature, dataFolderPath, databasePath, stringTableMetadata);

                var readedEvent = new ModMetadataLoadedEvent(modMetadata);

                command.Sender.Tell(readedEvent);
            });
        }
예제 #2
0
 internal void OnModMetadataLoaded(ModMetadataLoadedEvent eventModMetadata)
 {
     // TODO : check errors;
     _modMetadata = eventModMetadata.ModMetadata;
     _mainViewModel.MainMenuViewModel.CountryOperationsEnabled = true;
 }