Пример #1
0
		internal static bool do_BuildMod(object threadContext)
		{
			Interface.buildMod.SetReading();
			BuildProperties properties = BuildProperties.ReadBuildFile(modToBuild);
			if (!CreateModReferenceDlls(properties))
			{
				if (!buildAll)
				{
					Main.menuMode = Interface.errorMessageID;
				}
				return false;
			}
			LoadReferences();
			byte[] windowsData;
			byte[] otherData;
			if (properties.noCompile)
			{
				string modDir = modToBuild + Path.DirectorySeparatorChar;
				if (File.Exists(modDir + "All.dll"))
				{
					windowsData = File.ReadAllBytes(modDir + "All.dll");
					otherData = File.ReadAllBytes(modDir + "All.dll");
				}
				else if (File.Exists(modDir + "Windows.dll") && File.Exists(modDir + "Other.dll"))
				{
					windowsData = File.ReadAllBytes(modDir + "Windows.dll");
					otherData = File.ReadAllBytes(modDir + "Other.dll");
				}
				else
				{
					ErrorLogger.LogDllBuildError(modToBuild);
					if (!buildAll)
					{
						Main.menuMode = Interface.errorMessageID;
					}
					return false;
				}
			}
			else
			{
				Interface.buildMod.SetCompiling(0);
				windowsData = CompileMod(modToBuild, properties, true);
				Interface.buildMod.SetCompiling(1);
				otherData = CompileMod(modToBuild, properties, false);
				if (windowsData == null || otherData == null)
				{
					if (!buildAll)
					{
						Main.menuMode = Interface.errorMessageID;
					}
					return false;
				}
			}
			Interface.buildMod.SetBuildText();
			string file = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod";
			byte[] propertiesData = properties.ToBytes();
			TmodFile modFile = new TmodFile(file);
			using (MemoryStream memoryStream = new MemoryStream())
			{
				using (BinaryWriter writer = new BinaryWriter(memoryStream))
				{
					writer.Write(version);
					writer.Write(propertiesData.Length);
					writer.Write(propertiesData);
					writer.Flush();
					modFile.AddFile("Info", memoryStream.ToArray());
				}
			}
			using (MemoryStream memoryStream = new MemoryStream())
			{
				using (BinaryWriter writer = new BinaryWriter(memoryStream))
				{
					writer.Write(Path.GetFileName(modToBuild));
					string[] resources = Directory.GetFiles(modToBuild, "*", SearchOption.AllDirectories);
					foreach (string resource in resources)
					{
						if (properties.ignoreFile(resource.Replace(modToBuild + Path.DirectorySeparatorChar, null)))
						{
							continue;
						}
						if (Path.GetExtension(resource) == ".cs" && !properties.includeSource)
						{
							continue;
						}
						if (Path.GetFileName(resource) == "Thumbs.db")
						{
							continue;
						}
						if (resource.Substring(modToBuild.Length + 1) == "build.txt")
						{
							continue;
						}
						string resourcePath = resource.Replace(ModSourcePath + Path.DirectorySeparatorChar, null);
						resourcePath = resourcePath.Replace(Path.DirectorySeparatorChar, '/');
						byte[] buffer = File.ReadAllBytes(resource);
						writer.Write(resourcePath);
						writer.Write(buffer.Length);
						writer.Write(buffer);
					}
					writer.Write("end");
					writer.Flush();
					modFile.AddFile("Resources", memoryStream.ToArray());
				}
			}
			bool same = windowsData.Length == otherData.Length;
			if (same)
			{
				for (int k = 0; k < windowsData.Length; k++)
				{
					if (windowsData[k] != otherData[k])
					{
						same = false;
						break;
					}
				}
			}
			if (same)
			{
				modFile.AddFile("All", windowsData);
			}
			else
			{
				modFile.AddFile("Windows", windowsData);
				modFile.AddFile("Other", otherData);
			}
			modFile.Save();
			EnableMod(file);
			if (!buildAll)
			{
				Main.menuMode = reloadAfterBuild ? Interface.reloadModsID : 0;
			}
			return true;
		}
Пример #2
0
 internal static bool do_BuildMod(object threadContext)
 {
     Interface.buildMod.SetReading();
     BuildProperties properties = ReadBuildProperties(modToBuild);
     if (properties == null)
     {
         if (!buildAll)
         {
             Main.menuMode = Interface.errorMessageID;
         }
         return false;
     }
     LoadReferences();
     string file1 = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod1";
     string file2 = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod2";
     Interface.buildMod.SetCompiling();
     if (!CompileMod(modToBuild, properties, true) || !CompileMod(modToBuild, properties, false))
     {
         File.Delete(file1);
         File.Delete(file2);
         if (!buildAll)
         {
             Main.menuMode = Interface.errorMessageID;
         }
         return false;
     }
     Interface.buildMod.SetBuildText();
     string file = ModPath + Path.DirectorySeparatorChar + Path.GetFileName(modToBuild) + ".tmod";
     byte[] propertiesData = PropertiesToBytes(properties);
     TmodFile modFile = new TmodFile(file);
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (BinaryWriter writer = new BinaryWriter(memoryStream))
         {
             writer.Write(propertiesData.Length);
             writer.Write(propertiesData);
             writer.Write(Path.GetFileName(modToBuild));
             string[] resources = Directory.GetFiles(modToBuild, "*", SearchOption.AllDirectories);
             foreach (string resource in resources)
             {
                 if (Path.GetExtension(resource) == ".cs")
                 {
                     continue;
                 }
                 if (resource.Substring(modToBuild.Length + 1) == "build.txt")
                 {
                     continue;
                 }
                 string resourcePath = resource.Replace(ModSourcePath + Path.DirectorySeparatorChar, null);
                 resourcePath = resourcePath.Replace(Path.DirectorySeparatorChar, '/');
                 byte[] buffer = File.ReadAllBytes(resource);
                 writer.Write(resourcePath);
                 writer.Write(buffer.Length);
                 writer.Write(buffer);
             }
             writer.Write("end");
             writer.Flush();
             modFile.AddFile("Resources", memoryStream.ToArray());
         }
     }
     modFile.AddFile("Windows", File.ReadAllBytes(file1));
     modFile.AddFile("Other", File.ReadAllBytes(file2));
     modFile.Save();
     File.Delete(file1);
     File.Delete(file2);
     EnableMod(file);
     if (!buildAll)
     {
         Main.menuMode = reloadAfterBuild ? Interface.reloadModsID : 0;
     }
     return true;
 }