TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ Extract()

Task Terraria.ModLoader.UI.UIExtractMod.Extract ( )
inlineprivate

Definition at line 39 of file UIExtractMod.cs.

40 {
41 StreamWriter log = null;
42 IDisposable modHandle = null;
43 try
44 {
45 string modReferencesPath = Path.Combine(ModCompile.ModSourcePath, "ModAssemblies");
46 string oldModReferencesPath = Path.Combine(ModCompile.ModSourcePath, "Mod Libraries");
47 if (Directory.Exists(oldModReferencesPath) && !Directory.Exists(modReferencesPath))
48 {
49 Logging.tML.Info((object)$"Migrating from \"{oldModReferencesPath}\" to \"{modReferencesPath}\"");
50 Directory.Move(oldModReferencesPath, modReferencesPath);
51 Logging.tML.Info((object)"Moving old ModAssemblies folder to new location migration success");
52 }
53 string dir = Path.Combine(Main.SavePath, "ModReader", mod.Name);
54 if (Directory.Exists(dir))
55 {
56 Directory.Delete(dir, recursive: true);
57 }
58 Directory.CreateDirectory(dir);
59 log = new StreamWriter(Path.Combine(dir, "extract.log"))
60 {
61 AutoFlush = true
62 };
63 if (mod.properties.hideCode)
64 {
65 log.WriteLine(Language.GetTextValue("tModLoader.ExtractHideCodeMessage"));
66 }
67 else if (!mod.properties.includeSource)
68 {
69 log.WriteLine(Language.GetTextValue("tModLoader.ExtractNoSourceCodeMessage"));
70 }
71 if (mod.properties.hideResources)
72 {
73 log.WriteLine(Language.GetTextValue("tModLoader.ExtractHideResourcesMessage"));
74 }
75 log.WriteLine(Language.GetTextValue("tModLoader.ExtractFileListing"));
76 int i = 0;
77 modHandle = mod.modFile.Open();
78 foreach (TmodFile.FileEntry entry in mod.modFile)
79 {
80 _cts.Token.ThrowIfCancellationRequested();
81 string name = entry.Name;
83 DisplayText = name;
84 base.Progress = (float)i++ / (float)mod.modFile.Count;
85 if (name == "extract.log")
86 {
87 continue;
88 }
89 if (codeExtensions.Contains(Path.GetExtension(name)) ? mod.properties.hideCode : mod.properties.hideResources)
90 {
91 log.Write("[hidden] " + name);
92 continue;
93 }
94 log.WriteLine(name);
95 string path = Path.Combine(dir, name);
96 Directory.CreateDirectory(Path.GetDirectoryName(path));
97 using (FileStream dst = File.OpenWrite(path))
98 {
99 using Stream src = mod.modFile.GetStream(entry);
100 if (converter != null)
101 {
102 converter(src, dst);
103 }
104 else
105 {
106 src.CopyTo(dst);
107 }
108 }
109 if (name == mod.Name + ".dll")
110 {
111 Directory.CreateDirectory(modReferencesPath);
112 File.Copy(path, Path.Combine(modReferencesPath, $"{mod.Name}_v{mod.modFile.Version}.dll"), overwrite: true);
113 log?.WriteLine("You can find this mod's .dll files under " + Path.GetFullPath(modReferencesPath) + " for easy mod collaboration!");
114 }
115 if (name == mod.Name + ".xml" && !mod.properties.hideCode)
116 {
117 Directory.CreateDirectory(modReferencesPath);
118 File.Copy(path, Path.Combine(modReferencesPath, $"{mod.Name}_v{mod.modFile.Version}.xml"), overwrite: true);
119 log?.WriteLine("You can find this mod's documentation .xml file under " + Path.GetFullPath(modReferencesPath) + " for easy mod collaboration!");
120 }
121 }
122 Utils.OpenFolder(dir);
123 }
125 {
126 log?.WriteLine("Extraction was cancelled.");
127 return Task.FromResult(result: false);
128 }
129 catch (Exception e)
130 {
131 log?.WriteLine(e);
132 Logging.tML.Error((object)Language.GetTextValue("tModLoader.ExtractErrorWhileExtractingMod", mod.Name), e);
133 Main.menuMode = gotoMenu;
134 return Task.FromResult(result: false);
135 }
136 finally
137 {
138 log?.Close();
139 modHandle?.Dispose();
140 }
141 Main.menuMode = gotoMenu;
142 return Task.FromResult(result: true);
143 }
static string GetTextValue(string key)
Retrieves the text value for a specified localization key. The text returned will be for the currentl...
Definition Language.cs:35
Contains methods to access or retrieve localization values. The Localization Guideteaches more about ...
Definition Language.cs:12
static bool Reverse(ref string resourceName, out Action< Stream, Stream > converter)
readonly TmodFile modFile
Definition LocalMod.cs:7
readonly BuildProperties properties
Definition LocalMod.cs:9
static readonly string ModSourcePath
Definition ModCompile.cs:61
CancellationTokenSource _cts
static readonly IList< string > codeExtensions

References Terraria.ModLoader.UI.UIExtractMod._cts, Terraria.ModLoader.UI.UIExtractMod.codeExtensions, Terraria.ModLoader.UI.UIProgress.DisplayText, Terraria.Localization.Language.GetTextValue(), Terraria.ModLoader.UI.UIProgress.gotoMenu, Terraria.ModLoader.UI.UIExtractMod.mod, Terraria.ModLoader.Core.LocalMod.modFile, Terraria.ModLoader.Core.ModCompile.ModSourcePath, Terraria.ModLoader.Core.LocalMod.Name, Terraria.Utils.OpenFolder(), Terraria.ModLoader.Core.LocalMod.properties, Terraria.ModLoader.Core.ContentConverters.Reverse(), Terraria.Main.SavePath, and Terraria.ModLoader.Logging.tML.

Referenced by Terraria.ModLoader.UI.UIExtractMod.OnActivate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: