string Transform(GenFile file) { if (file.Namespace != null) { _names.TopNamespace = IdentifierName(MakeCamel(file.Namespace[0])); foreach (string name in file.Namespace.Skip(1)) { var temp = IdentifierName(MakeCamel(name)); _names.TopNamespace = QualifiedName(_names.TopNamespace, temp); } } var ns = NamespaceDeclaration(_names.TopNamespace); foreach (var def in file.NestedTypes) { ns = ns.AddMembers(Transform(def).ToArray()); } var cu = CompilationUnit().AddUsings( UsingDirective(ParseName("Capnp")), UsingDirective(ParseName("Capnp.Rpc")), UsingDirective(ParseName("System")), UsingDirective(ParseName("System.Collections.Generic")), UsingDirective(ParseName("System.Threading")), UsingDirective(ParseName("System.Threading.Tasks"))); cu = cu.AddMembers(ns); return(cu.NormalizeWhitespace().ToFullString()); }
internal string Transform(GenFile file) { NameSyntax topNamespace = GenNames.NamespaceName(file.Namespace) ?? _names.TopNamespace; var ns = NamespaceDeclaration(topNamespace); foreach (var def in file.NestedTypes) { ns = ns.AddMembers(Transform(def).ToArray()); } var psc = TransformForPipeliningSupport(file); if (psc != null) { ns = ns.AddMembers(psc); } var cu = CompilationUnit().AddUsings( UsingDirective(ParseName("Capnp")), UsingDirective(ParseName("Capnp.Rpc")), UsingDirective(ParseName("System")), UsingDirective(ParseName("System.Collections.Generic")), UsingDirective(ParseName("System.Threading")), UsingDirective(ParseName("System.Threading.Tasks"))); cu = cu.AddMembers(ns); return(cu.NormalizeWhitespace().ToFullString()); }
static void Convert() { LongEventHandler.QueueLongEvent(() => { try { const string suffix = "-preconvert"; var saveName = $"{GenFile.SanitizedFileName(Multiplayer.session.gameName)}{suffix}"; new FileInfo(Path.Combine(Multiplayer.ReplaysDir, saveName + ".zip")).Delete(); Replay.ForSaving(saveName).WriteCurrentData(); } catch (Exception e) { Log.Warning($"Convert to singleplayer failed to write pre-convert file: {e}"); } Find.GameInfo.permadeathMode = false; HostUtil.SetAllUniqueIds(Multiplayer.GlobalIdBlock.Current); Multiplayer.StopMultiplayer(); var doc = SaveLoad.SaveGameToDoc(); MemoryUtility.ClearAllMapsAndWorld(); Current.Game = new Game(); Current.Game.InitData = new GameInitData(); Current.Game.InitData.gameToLoad = "play"; LoadPatch.gameToLoad = new TempGameData(doc, new byte[0]); }, "Play", "MpConvertingToSp", true, null); }
public static IEnumerable <string> LinesFromFile(string filePath) { string rawText = GenFile.TextFromRawFile(filePath); foreach (string line in GenText.LinesFromString(rawText)) { yield return(line); } }
internal string Transform(GenFile file) { _names.NullableEnable = file.NullableEnable ?? _options.NullableEnableDefault; NameSyntax topNamespace = GenNames.NamespaceName(file.Namespace) ?? _names.TopNamespace; var ns = NamespaceDeclaration(topNamespace); if (file.EmitNullableDirective) { ns = ns.WithLeadingTrivia( Trivia( NullableDirectiveTrivia( Token(_names.NullableEnable ? SyntaxKind.EnableKeyword : SyntaxKind.DisableKeyword), true))) .WithTrailingTrivia( Trivia( NullableDirectiveTrivia( Token(SyntaxKind.RestoreKeyword), true))); } foreach (var def in file.NestedTypes) { ns = ns.AddMembers(Transform(def).ToArray()); } var psc = TransformForPipeliningSupport(file); if (psc != null) { ns = ns.AddMembers(psc); } var cu = CompilationUnit().AddUsings( UsingDirective(ParseName("Capnp")), UsingDirective(ParseName("Capnp.Rpc")), UsingDirective(ParseName("System")), UsingDirective(ParseName("System.Collections.Generic"))); if (_names.NullableEnable) { cu = cu.AddUsings( UsingDirective(ParseName("System.Diagnostics.CodeAnalysis"))); } cu = cu.AddUsings( UsingDirective(ParseName("System.Threading")), UsingDirective(ParseName("System.Threading.Tasks"))); cu = cu.AddMembers(ns); return(cu.NormalizeWhitespace(" ", Environment.NewLine).ToFullString()); }
protected override void DoFileInteraction(string mapName) { mapName = GenFile.SanitizedFileName(mapName); LongEventHandler.QueueLongEvent(delegate { GameDataSaveLoader.SaveGame(mapName); }, "SavingLongEvent", doAsynchronously: false, null); Messages.Message("SavedAs".Translate(mapName), MessageTypeDefOf.SilentInput, historical: false); PlayerKnowledgeDatabase.Save(); Close(); }
protected override void DoFileInteraction(string mapName) { mapName = GenFile.SanitizedFileName(mapName); LongEventHandler.QueueLongEvent(delegate { GameDataSaveLoader.SaveGame(mapName); }, "SavingLongEvent", false, null); Messages.Message("SavedAs".Translate(new object[] { mapName }), MessageTypeDefOf.SilentInput, false); PlayerKnowledgeDatabase.Save(); this.Close(true); }
public override bool Validate(string str) { if (str.Length > 30) { return(false); } if (GenFile.SanitizedFileName(str) != str) { return(false); } fileExists = new FileInfo(Path.Combine(Multiplayer.ReplaysDir, $"{str}.zip")).Exists; return(true); }
ClassDeclarationSyntax TransformForPipeliningSupport(GenFile file) { var classDecl = default(ClassDeclarationSyntax); var q = new Queue <TypeDefinition>(); foreach (var inner in file.NestedTypes) { q.Enqueue(inner); } while (q.Count > 0) { var cur = q.Dequeue(); if (cur.Tag == TypeTag.Interface && _interfaceGen.RequiresPipeliningSupport(cur)) { var members = _interfaceGen.MakePipeliningSupport(cur).ToArray(); if (members.Length > 0) { if (classDecl == null) { classDecl = ClassDeclaration(_names.MakePipeliningSupportExtensionClassName(file).Identifier) .AddModifiers(Public, Static, Partial); } classDecl = classDecl.AddMembers(members); } } foreach (var inner in cur.NestedTypes) { q.Enqueue(inner); } } return(classDecl); }
public void AddNamesFromFile(PawnNameSlot slot, Gender gender, string fileName) { AddNames(slot, gender, GenFile.LinesFromFile("Names/" + fileName)); }
public Name MakePipeliningSupportExtensionClassName(GenFile file) { return(new Name(string.Format(PipeliningExtensionsClassFormat, Path.GetFileNameWithoutExtension(file.Name).Replace(".", "_")))); }
private static bool IsValidFileName(string label) { return(GenFile.SanitizedFileName(label) == label); }
public BackGroundFileReader_Tests() { GenFile.Create(FileSystemMock, DefaultPath); _partitionStreamMock = new PartitionStreamMock(Config.ChunkSize); }
public Dialog_SaveGame() { title = "MpSaveGameAs".Translate(); curName = GenFile.SanitizedFileName(Multiplayer.session.gameName); }