// TODO: The package should be mounted into its own context to avoid name collisions with installed files public static bool ExtractFromPackage(string srcPath, string package, string annotation, string[] files, string destPath, Action <string> onProgress, Action <string> onError) { if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } Log.Write("debug", "Mounting {0}".F(srcPath)); GlobalFileSystem.Mount(srcPath); Log.Write("debug", "Mounting {0}".F(package)); GlobalFileSystem.Mount(package, annotation); foreach (var file in files) { var dest = Path.Combine(destPath, file); if (File.Exists(dest)) { File.Delete(dest); } using (var sourceStream = GlobalFileSystem.Open(file)) using (var destStream = File.Create(dest)) { Log.Write("debug", "Extracting {0} to {1}".F(file, dest)); onProgress("Extracting " + file); destStream.Write(sourceStream.ReadAllBytes()); } } return(true); }
public Map PrepareMap(string uid) { if (LoadScreen != null) { LoadScreen.Display(); } if (MapCache[uid].Status != MapStatus.Available) { throw new InvalidDataException("Invalid map uid: {0}".F(uid)); } // Operate on a copy of the map to avoid gameplay state leaking into the cache var map = new Map(MapCache[uid].Map.Path); LoadTranslations(map); // Reinit all our assets InitializeLoaders(); GlobalFileSystem.LoadFromManifest(Manifest); // Mount map package so custom assets can be used. TODO: check priority. GlobalFileSystem.Mount(GlobalFileSystem.OpenPackage(map.Path, null, int.MaxValue)); using (new Support.PerfTimer("Map.PreloadRules")) map.PreloadRules(); using (new Support.PerfTimer("Map.SequenceProvider.Preload")) map.SequenceProvider.Preload(); VoxelProvider.Initialize(Manifest.VoxelSequences, map.VoxelSequenceDefinitions); VoxelLoader.Finish(); return(map); }
public CncInstallMusicLogic(Widget widget, Ruleset modRules, Action onExit) { var installButton = widget.GetOrNull <ButtonWidget>("INSTALL_BUTTON"); if (installButton != null) { Action afterInstall = () => { try { var path = new string[] { Platform.SupportDir, "Content", Game.modData.Manifest.Mod.Id }.Aggregate(Path.Combine); GlobalFileSystem.Mount(Path.Combine(path, "scores.mix")); GlobalFileSystem.Mount(Path.Combine(path, "transit.mix")); modRules.Music.Do(m => m.Value.Reload()); var musicPlayerLogic = (MusicPlayerLogic)installButton.Parent.LogicObject; musicPlayerLogic.BuildMusicTable(); } catch (Exception e) { Log.Write("debug", "Mounting the new mixfile and rebuild of scores list failed:\n{0}", e); } }; installButton.OnClick = () => Ui.OpenWindow("INSTALL_MUSIC_PANEL", new WidgetArgs() { { "afterInstall", afterInstall }, { "filesToCopy", new[] { "SCORES.MIX" } }, { "filesToExtract", new[] { "transit.mix" } }, }); installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length < 3; // HACK around music being split between transit.mix and scores.mix } }
// TODO: The package should be mounted into its own context to avoid name collisions with installed files public static bool ExtractFromPackage(string srcPath, string package, string[] files, string destPath, Action <string> onProgress, Action <string> onError) { if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } if (!GlobalFileSystem.Exists(srcPath)) { onError("Cannot find " + package); return(false); } GlobalFileSystem.Mount(srcPath); if (!GlobalFileSystem.Exists(package)) { onError("Cannot find " + package); return(false); } GlobalFileSystem.Mount(package); foreach (string s in files) { var destFile = Path.Combine(destPath, s); using (var sourceStream = GlobalFileSystem.Open(s)) using (var destStream = File.Create(destFile)) { onProgress("Extracting " + s); destStream.Write(sourceStream.ReadAllBytes()); } } return(true); }
public ModData(string mod, bool useLoadScreen = false) { Languages = new string[0]; Manifest = new Manifest(mod); ObjectCreator = new ObjectCreator(Manifest); Manifest.LoadCustomData(ObjectCreator); if (useLoadScreen) { LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value); LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value)); LoadScreen.Display(); } WidgetLoader = new WidgetLoader(this); RulesetCache = new RulesetCache(this); RulesetCache.LoadingProgress += HandleLoadingProgress; MapCache = new MapCache(this); var spriteLoaders = new List <ISpriteLoader>(); foreach (var format in Manifest.SpriteFormats) { var loader = ObjectCreator.FindType(format + "Loader"); if (loader == null || !loader.GetInterfaces().Contains(typeof(ISpriteLoader))) { throw new InvalidOperationException("Unable to find a sprite loader for type '{0}'.".F(format)); } spriteLoaders.Add((ISpriteLoader)ObjectCreator.CreateBasic(loader)); } SpriteLoaders = spriteLoaders.ToArray(); var sequenceFormat = Manifest.Get <SpriteSequenceFormat>(); var sequenceLoader = ObjectCreator.FindType(sequenceFormat.Type + "Loader"); var ctor = sequenceLoader != null?sequenceLoader.GetConstructor(new[] { typeof(ModData) }) : null; if (sequenceLoader == null || !sequenceLoader.GetInterfaces().Contains(typeof(ISpriteSequenceLoader)) || ctor == null) { throw new InvalidOperationException("Unable to find a sequence loader for type '{0}'.".F(sequenceFormat.Type)); } SpriteSequenceLoader = (ISpriteSequenceLoader)ctor.Invoke(new[] { this }); SpriteSequenceLoader.OnMissingSpriteError = s => Log.Write("debug", s); // HACK: Mount only local folders so we have a half-working environment for the asset installer GlobalFileSystem.UnmountAll(); foreach (var dir in Manifest.Folders) { GlobalFileSystem.Mount(dir); } defaultRules = Exts.Lazy(() => RulesetCache.LoadDefaultRules()); initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; }
// TODO: The package should be mounted into its own context to avoid name collisions with installed files public static bool ExtractFromPackage(string srcPath, string package, string annotation, Dictionary <string, string[]> filesByDirectory, string destPath, bool overwrite, Action <string> onProgress, Action <string> onError) { if (!Directory.Exists(destPath)) { Directory.CreateDirectory(destPath); } Log.Write("debug", "Mounting {0}".F(srcPath)); GlobalFileSystem.Mount(srcPath); Log.Write("debug", "Mounting {0}".F(package)); GlobalFileSystem.Mount(package, annotation); foreach (var directory in filesByDirectory) { var targetDir = directory.Key; foreach (var file in directory.Value) { var containingDir = Path.Combine(destPath, targetDir); var dest = Path.Combine(containingDir, file.ToLowerInvariant()); if (File.Exists(dest)) { if (overwrite) { File.Delete(dest); } else { Log.Write("debug", "Skipping {0}".F(dest)); continue; } } Directory.CreateDirectory(containingDir); using (var sourceStream = GlobalFileSystem.Open(file)) using (var destStream = File.Create(dest)) { Log.Write("debug", "Extracting {0} to {1}".F(file, dest)); onProgress("Extracting " + file); destStream.Write(sourceStream.ReadAllBytes()); } } } return(true); }
public void Run(ModData modData, string[] args) { Game.ModData = modData; var map = new Map(args[1]); GlobalFileSystem.UnmountAll(); foreach (var dir in Game.ModData.Manifest.Folders) { GlobalFileSystem.Mount(dir); } var minimap = Minimap.RenderMapPreview(map.Rules.TileSets[map.Tileset], map, true); var dest = Path.GetFileNameWithoutExtension(args[1]) + ".png"; minimap.Save(dest); Console.WriteLine(dest + " saved."); }
public ModData(string mod) { Languages = new string[0]; Manifest = new Manifest(mod); ObjectCreator = new ObjectCreator(Manifest); LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value); LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value)); LoadScreen.Display(); WidgetLoader = new WidgetLoader(this); RulesetCache = new RulesetCache(this); RulesetCache.LoadingProgress += HandleLoadingProgress; MapCache = new MapCache(this); var loaders = new List <ISpriteLoader>(); foreach (var format in Manifest.SpriteFormats) { var loader = ObjectCreator.FindType(format + "Loader"); if (loader == null || !loader.GetInterfaces().Contains(typeof(ISpriteLoader))) { throw new InvalidOperationException("Unable to find a sprite loader for type '{0}'.".F(format)); } loaders.Add((ISpriteLoader)ObjectCreator.CreateBasic(loader)); } SpriteLoaders = loaders.ToArray(); // HACK: Mount only local folders so we have a half-working environment for the asset installer GlobalFileSystem.UnmountAll(); foreach (var dir in Manifest.Folders) { GlobalFileSystem.Mount(dir); } defaultRules = Exts.Lazy(() => RulesetCache.LoadDefaultRules()); initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; }
public ModData(string mod) { Languages = new string[0]; Manifest = new Manifest(mod); ObjectCreator = new ObjectCreator(Manifest); LoadScreen = ObjectCreator.CreateObject <ILoadScreen>(Manifest.LoadScreen.Value); LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value)); LoadScreen.Display(); WidgetLoader = new WidgetLoader(this); RulesetCache = new RulesetCache(this); RulesetCache.LoadingProgress += HandleLoadingProgress; MapCache = new MapCache(this); // HACK: Mount only local folders so we have a half-working environment for the asset installer GlobalFileSystem.UnmountAll(); foreach (var dir in Manifest.Folders) { GlobalFileSystem.Mount(dir); } defaultRules = Exts.Lazy(() => RulesetCache.LoadDefaultRules()); initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; }
internal static void Initialize(Arguments args) { Console.WriteLine("Platform is {0}", Platform.CurrentPlatform); AppDomain.CurrentDomain.AssemblyResolve += GlobalFileSystem.ResolveAssembly; InitializeSettings(args); Log.AddChannel("perf", "perf.log"); Log.AddChannel("debug", "debug.log"); Log.AddChannel("sync", "syncreport.log"); Log.AddChannel("server", "server.log"); Log.AddChannel("sound", "sound.log"); Log.AddChannel("graphics", "graphics.log"); Log.AddChannel("geoip", "geoip.log"); if (Settings.Server.DiscoverNatDevices) { UPnP.TryNatDiscovery(); } else { Settings.Server.NatDeviceAvailable = false; Settings.Server.AllowPortForward = false; } try { GeoIpDatabase = new DatabaseReader("GeoLite2-Country.mmdb"); } catch (Exception e) { Log.Write("geoip", "DatabaseReader failed: {0}", e); } GlobalFileSystem.Mount(Platform.GameDir); // Needed to access shaders var renderers = new[] { Settings.Graphics.Renderer, "Sdl2", null }; foreach (var r in renderers) { if (r == null) { throw new InvalidOperationException("No suitable renderers were found. Check graphics.log for details."); } Settings.Graphics.Renderer = r; try { Renderer = new Renderer(Settings.Graphics, Settings.Server); break; } catch (Exception e) { Log.Write("graphics", "{0}", e); Console.WriteLine("Renderer initialization failed. Fallback in place. Check graphics.log for details."); } } try { Sound.Create(Settings.Sound.Engine); } catch (Exception e) { Log.Write("sound", "{0}", e); Console.WriteLine("Creating the sound engine failed. Fallback in place. Check sound.log for details."); Settings.Sound.Engine = "Null"; Sound.Create(Settings.Sound.Engine); } Console.WriteLine("Available mods:"); foreach (var mod in ModMetadata.AllMods) { Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); } InitializeMod(Settings.Game.Mod, args); if (Settings.Server.DiscoverNatDevices) { RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.StoppingNatDiscovery); } }