Guest User

Untitled

a guest
Jun 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace AddAModOnAgeOfEmpireII
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. this.Text = "This Programme is made By Katsuie*";
  21. panel_type_drs.Visible = false;
  22. }
  23.  
  24.  
  25. /// <span class="code-SummaryComment"><summary></span>
  26. /// Executes a shell command synchronously.
  27. /// <span class="code-SummaryComment"></summary></span>
  28. /// <span class="code-SummaryComment"><param name="command">string command</param></span>
  29. /// <span class="code-SummaryComment"><returns>string, as output of the command.</returns></span>
  30. public void ExecuteCommandSync(object command)
  31. {
  32. //try
  33. //{
  34. // create the ProcessStartInfo using "cmd" as the program to be run,
  35. // and "/c " as the parameters.
  36. // Incidentally, /c tells cmd that we want it to execute the command that follows,
  37. // and then exit.
  38.  
  39. System.Diagnostics.ProcessStartInfo procStartInfo =
  40. new System.Diagnostics.ProcessStartInfo("drsbuild.exe", "" + command);
  41.  
  42. // The following commands are needed to redirect the standard output.
  43. // This means that it will be redirected to the Process.StandardOutput StreamReader.
  44. procStartInfo.RedirectStandardOutput = true;
  45. procStartInfo.UseShellExecute = false;
  46. // Do not create the black window.
  47. procStartInfo.CreateNoWindow = true;
  48. // Now we create a process, assign its ProcessStartInfo and start it
  49. System.Diagnostics.Process proc = new System.Diagnostics.Process();
  50. proc.StartInfo = procStartInfo;
  51. proc.Start();
  52. // Get the output into a string
  53. string result = proc.StandardOutput.ReadToEnd();
  54. // Display the command output.
  55. Console.WriteLine(result);
  56. //}
  57. //catch (Exception objException)
  58. //{
  59. // // Log the exception
  60. //}
  61. }
  62. /// <span class="code-SummaryComment"><summary></span>
  63. /// Execute the command Asynchronously.
  64. /// <span class="code-SummaryComment"></summary></span>
  65. /// <span class="code-SummaryComment"><param name="command">string command.</param></span>
  66. public void ExecuteCommandAsync(string command)
  67. {
  68. try
  69. {
  70. //Asynchronously start the Thread to process the Execute command request.
  71. Thread objThread = new Thread(new ParameterizedThreadStart(ExecuteCommandSync));
  72. //Make the thread as background thread.
  73. objThread.IsBackground = true;
  74. //Set the Priority of the thread.
  75. objThread.Priority = ThreadPriority.AboveNormal;
  76. //Start the thread.
  77. objThread.Start(command);
  78. }
  79. catch (ThreadStartException objException)
  80. {
  81. // Log the exception
  82. }
  83. catch (ThreadAbortException objException)
  84. {
  85. // Log the exception
  86. }
  87. catch (Exception objException)
  88. {
  89. // Log the exception
  90. }
  91. }
  92. public string folderPath;
  93.  
  94. public string AddQuotesIfRequired(string path)
  95. {
  96. return !string.IsNullOrEmpty(path) ?
  97. path.Contains(" ") ? "\"" + path + "\"" : path
  98. : string.Empty;
  99. }
  100. //add_mod("terrainHD", "terrain", "*.slp");
  101.  
  102. public bool flag;
  103. public void message()
  104. {
  105. if (folderPath == null)
  106. {
  107. MessageBox.Show("Choise Age of Rmpire II path !!! Click Browser");
  108. flag = false;
  109. }
  110. }
  111.  
  112.  
  113. private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
  114. {
  115. // Get the subdirectories for the specified directory.
  116. DirectoryInfo dir = new DirectoryInfo(sourceDirName);
  117.  
  118. if (!dir.Exists)
  119. {
  120. throw new DirectoryNotFoundException(
  121. "Source directory does not exist or could not be found: "
  122. + sourceDirName);
  123. }
  124.  
  125. DirectoryInfo[] dirs = dir.GetDirectories();
  126. // If the destination directory doesn't exist, create it.
  127. if (!Directory.Exists(destDirName))
  128. {
  129. Directory.CreateDirectory(destDirName);
  130. }
  131.  
  132. // Get the files in the directory and copy them to the new location.
  133. FileInfo[] files = dir.GetFiles();
  134. foreach (FileInfo file in files)
  135. {
  136. string temppath = Path.Combine(destDirName, file.Name);
  137. file.CopyTo(temppath, false);
  138. }
  139.  
  140. // If copying subdirectories, copy them and their contents to new location.
  141. if (copySubDirs)
  142. {
  143. foreach (DirectoryInfo subdir in dirs)
  144. {
  145. string temppath = Path.Combine(destDirName, subdir.Name);
  146. DirectoryCopy(subdir.FullName, temppath, copySubDirs);
  147. }
  148. }
  149. }
  150.  
  151. private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
  152. {
  153. MessageBox.Show($@"Pour tous ce qui est unitées et mines, faliase, bois ça se trouve dans Age Of Empire II/Data/graphics.drs
  154. {Environment.NewLine} Pour ce qui est terrain et fermes ça se trouve dans Age Of Empire II/Data/terrain.drs ");
  155.  
  156. }
  157.  
  158. private void parcourirToolStripMenuItem_Click(object sender, EventArgs e)
  159. {
  160. try
  161. {
  162. folderPath = "";
  163. FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
  164. if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
  165. {
  166. folderPath = folderBrowserDialog1.SelectedPath;
  167. if (folderPath == "")
  168. flag = false;
  169. else
  170. flag = true;
  171. if (!Directory.Exists($@"Data\") && !Directory.Exists($@"dll\"))
  172. {
  173. Directory.CreateDirectory($@"Data\");
  174. Directory.CreateDirectory($@"dll\");
  175. if (folderPath != "")
  176. {
  177. DirectoryCopy($@"{folderPath}\Data\", $@"Data\", true);
  178. DirectoryInfo d = new DirectoryInfo($@"{folderPath}");
  179. FileInfo[] Files_dll = d.GetFiles("*.dll"); //Getting Text files
  180. for (int i = 0; i < Files_dll.Count(); i++)
  181. {
  182. Files_dll[i].CopyTo($@"dll\{Files_dll[i]}", false);
  183. }
  184.  
  185. }
  186. }
  187. }
  188. }
  189. catch (Exception ex)
  190. {
  191. MessageBox.Show("" + ex);
  192. }
  193. }
  194.  
  195. public void add_mod(string s, string drs, string ext)
  196. {
  197. DirectoryInfo d_resp = new DirectoryInfo($@"{s}\resp");//Assuming Test is your Folder
  198. DirectoryInfo d = new DirectoryInfo($@"{s}\");//Assuming Test is your Folder
  199. FileInfo[] Files_resp = d_resp.GetFiles(ext); //Getting Text files
  200. FileInfo[] Files = d.GetFiles(ext); //Getting Text files
  201. string cmd = "";
  202. string Arg = "/e ";
  203. // on extrait
  204. for (int i = 0; i < Files.Count(); i++)
  205. {
  206. if (Files_resp.Count() == 0) //si le fichier est vide alors on sauvegard la version slp du graphic.drs
  207. {
  208. cmd = $@"{Arg} ""{folderPath}\data\{drs}.drs"" {Files[i].ToString()} /o {s}\resp\ ";
  209. Thread.Sleep(500); //sinon le process bug
  210. ExecuteCommandAsync(cmd);
  211. Thread.Sleep(500); //sinon le process bug
  212. }
  213. }
  214. Arg = "/r";
  215. cmd = "";
  216. //ramplace
  217. cmd = $@"{Arg} ""{folderPath}\Data\{drs}.drs"" {s}\{ext}";
  218. ExecuteCommandAsync(cmd);
  219.  
  220.  
  221. }
  222.  
  223. //back_to_old_mod("HdFirev2", "graphics", "*.slp");
  224. public void back_to_old_mod(string s, string drs, string ext)
  225. {
  226. DirectoryInfo d_resp = new DirectoryInfo($@"{s}\resp");//Assuming Test is your Folder
  227. DirectoryInfo d = new DirectoryInfo($@"{s}\");//Assuming Test is your Folder
  228.  
  229. string cmd = "";
  230. string Arg = "/r ";
  231. //on remplace par les anciens
  232. cmd = $@"{Arg} ""{folderPath}\Data\{drs}.drs"" {s}\resp\{ext} ";
  233. ExecuteCommandAsync(cmd);
  234. }
  235. private void button2_Click(object sender, EventArgs e)
  236. {
  237. if (radioButton_AOENormal.Checked)
  238. {
  239. if (modpath == "")
  240. {
  241. FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
  242. modpath = "";
  243. if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
  244. {
  245. modpath = folderBrowserDialog1.SelectedPath;
  246. if (radioButton_Terrain.Checked)
  247. back_to_old_mod(modpath, "terrain", "*.slp");
  248. if (radioButton_Graphic.Checked)
  249. back_to_old_mod(modpath, "graphics", "*.slp");
  250. if (radioButton_Interfac.Checked)
  251. back_to_old_mod(modpath, "interfac", "*.slp");
  252. }
  253. }
  254. else
  255. {
  256. if (radioButton_Terrain.Checked)
  257. back_to_old_mod(modpath, "terrain", "*.slp");
  258. if (radioButton_Graphic.Checked)
  259. back_to_old_mod(modpath, "graphics", "*.slp");
  260. if (radioButton_Interfac.Checked)
  261. back_to_old_mod(modpath, "interfac", "*.slp");
  262. }
  263.  
  264. }
  265. //C:\Program Files (x86)\Steam\steamapps\common\Age2HD\resources\_common\drs\graphics
  266. if (radioButton_AOEHD.Checked)
  267. {
  268. FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
  269. modpath = "";
  270. if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
  271. {
  272. modpath = folderBrowserDialog1.SelectedPath;
  273. Directory.CreateDirectory($@"{modpath}\respHd");
  274. DirectoryInfo d_resphd = new DirectoryInfo($@"{modpath}\respHd");//Assuming Test is your Folder
  275. DirectoryInfo d_pourhd = new DirectoryInfo($@"{modpath}\PourHD");
  276. DirectoryInfo d = new DirectoryInfo($@"{modpath}\");
  277. FileInfo[] Files = d.GetFiles("*.slp"); //Getting Text files
  278. FileInfo[] FilesPourHd = d_pourhd.GetFiles("*.slp");
  279. FileInfo[] Fileresphd = d_resphd.GetFiles("*.slp");
  280.  
  281. string steamPath = "";
  282. steamPath = $@" C:\Program Files (x86)\Steam\steamapps\common\Age2HD\resources\_common\drs\graphics ";
  283. var verif = Directory.Exists(@" C:\Program Files (x86)\Steam\steamapps\common\Age2HD\resources\_common\drs\graphics");
  284. if (!verif)//!Directory.Exists(@" C:\Program Files (x86)\Steam\steamapps\common\Age2HD\resources\_common\drs\graphics")) ;
  285. {
  286. steamPath = "";
  287. MessageBox.Show(@"Veuillez parcourir: Steam\steamapps\common\Age2HD\resources\_common\drs\graphics");
  288. FolderBrowserDialog folderBrowserDialog2 = new FolderBrowserDialog();
  289. if (folderBrowserDialog2.ShowDialog() == DialogResult.OK)
  290. {
  291. steamPath = folderBrowserDialog2.SelectedPath;
  292. }
  293. }
  294. DirectoryInfo d_steam = new DirectoryInfo(steamPath);
  295. FileInfo[] filesSteam = d_steam.GetFiles("*.slp");
  296. // Get the files in the directory and copy them to the new location.
  297.  
  298.  
  299. //on supprime les fichier dans Steam\steamapps\common\Age2HD\resources\_common\drs\graphics
  300. foreach (FileInfo file in FilesPourHd)
  301. {
  302. foreach (FileInfo f in filesSteam)
  303. {
  304. if (file.Name == f.Name) // on supprime les fichiers qui sont identique au mod
  305. {
  306. f.Delete();
  307. }
  308. }
  309. }
  310.  
  311. //on copie les fichier de sauvegarder dans respHD
  312. foreach (FileInfo file in FilesPourHd)
  313. {
  314. foreach (FileInfo f in Fileresphd)
  315. {
  316. if (file.Name == f.Name)
  317. {
  318. string temppath = Path.Combine(steamPath, file.Name);
  319. f.CopyTo(temppath, false);
  320. }
  321. }
  322. }
  323.  
  324.  
  325. }
  326. }
  327. }
  328. public string modpath;
  329. private void button1_Click(object sender, EventArgs e)
  330. {
  331. if (radioButton_AOENormal.Checked)
  332. {
  333. FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
  334. modpath = "";
  335. if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
  336. {
  337. modpath = folderBrowserDialog1.SelectedPath;
  338. if (!Directory.Exists($@"{modpath}\resp"))
  339. Directory.CreateDirectory($@"{modpath}\resp");
  340. if (radioButton_Terrain.Checked)
  341. add_mod(modpath, "terrain", "*.slp");
  342. if (radioButton_Graphic.Checked)
  343. add_mod(modpath, "graphics", "*.slp");
  344. if (radioButton_Interfac.Checked)
  345. add_mod(modpath, "interfac", "*.slp");
  346. }
  347. }
  348. if(radioButton_AOEHD.Checked)
  349. {
  350. FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
  351. modpath = "";
  352. if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
  353. {
  354. modpath = folderBrowserDialog1.SelectedPath;
  355. Directory.CreateDirectory($@"{modpath}\respHd");
  356. DirectoryInfo d_resphd = new DirectoryInfo($@"{modpath}\respHd");//Assuming Test is your Folder
  357. DirectoryInfo d_pourhd = new DirectoryInfo($@"{modpath}\PourHD");
  358. DirectoryInfo d = new DirectoryInfo($@"{modpath}\");
  359. FileInfo[] Files = d.GetFiles("*.slp"); //Getting Text files
  360. FileInfo[] FilesPourHd = d_pourhd.GetFiles("*.slp");
  361. FileInfo[] Fileresp = d_resphd.GetFiles("*.slp");
  362.  
  363. string steamPath = "";
  364. steamPath = $@" C:\Program Files (x86)\Steam\steamapps\common\Age2HD\resources\_common\drs\graphics ";
  365. var verif = Directory.Exists(@" C:\Program Files (x86)\Steam\steamapps\common\Age2HD\resources\_common\drs\graphics");
  366. if (!verif)//!Directory.Exists(@" C:\Program Files (x86)\Steam\steamapps\common\Age2HD\resources\_common\drs\graphics")) ;
  367. {
  368. steamPath = "";
  369. MessageBox.Show(@"Veuillez parcourir: Steam\steamapps\common\Age2HD\resources\_common\drs\graphics");
  370. FolderBrowserDialog folderBrowserDialog2 = new FolderBrowserDialog();
  371. if (folderBrowserDialog2.ShowDialog() == DialogResult.OK)
  372. {
  373. steamPath = folderBrowserDialog2.SelectedPath;
  374. }
  375. }
  376. DirectoryInfo d_steam = new DirectoryInfo(steamPath);
  377. FileInfo[] filesSteam = d_steam.GetFiles("*.slp");
  378. // Get the files in the directory and copy them to the new location.
  379.  
  380. //on copie les fichier de Steam\steamapps\common\Age2HD\resources\_common\drs\graphics dans le répértoir respHd
  381. foreach (FileInfo file in filesSteam)
  382. {
  383. foreach (FileInfo f in FilesPourHd)
  384. {
  385. if (file.Name == f.Name)
  386. {
  387. string temppath = Path.Combine($@"{modpath}\respHd", file.Name);
  388. file.CopyTo(temppath, true);
  389. }
  390. }
  391. }
  392.  
  393. //on supprime les fichier dans Steam\steamapps\common\Age2HD\resources\_common\drs\graphics
  394. foreach (FileInfo file in FilesPourHd)
  395. {
  396. foreach (FileInfo f in filesSteam)
  397. {
  398. if (file.Name == f.Name) // on supprime les fichiers qui sont identique au mod
  399. {
  400. f.Delete();
  401. }
  402. }
  403. }
  404. //on copie les fichier du mode dans Steam\steamapps\common\Age2HD\resources\_common\drs\graphics
  405. foreach (FileInfo file in FilesPourHd)
  406. {
  407. string temppath = Path.Combine(steamPath, file.Name);
  408. file.CopyTo(temppath, false);
  409.  
  410. }
  411. }
  412. }
  413. }
  414.  
  415. private void infoToolStripMenuItem_Click(object sender, EventArgs e)
  416. {
  417.  
  418.  
  419.  
  420.  
  421.  
  422. }
  423.  
  424. private void formatDeFichierToolStripMenuItem_Click(object sender, EventArgs e)
  425. {
  426. MessageBox.Show(@" je rappel le chemin: Age Of Empire II/data
  427. Les fichiers .slp de graphic.drs doivent avoir gra devant leur nom par exmple: gra00576.slp"
  428. +Environment.NewLine+ "Les fichiers .slp de terrain.drs doivent avoir ter devant leur nom par exmple: ter15001.slp"
  429. +Environment.NewLine+ " Les fichiers .slp de Interface.drs doivent avoir int leur nom par exmple: int50500.bin"
  430. +Environment.NewLine + "Les Fichiers doivent avoir un nombre avec 5 zéros par exemple: gra00001.slp ");
  431. }
  432.  
  433. private void formatDeFichierAOE2HDToolStripMenuItem_Click(object sender, EventArgs e)
  434. {
  435. MessageBox.Show("Pour les fichier du HDLa régle des 5 zéros ne s'applique pas ainsi que les préfix Exemple de fichier: 576.slp ou 1636.slp ");
  436. }
  437.  
  438. private void renomeUnFichierToolStripMenuItem_Click(object sender, EventArgs e)
  439. {
  440. var f = new RenameFile();
  441. f.ShowDialog();
  442. }
  443.  
  444. private void radioButton_AOENormal_CheckedChanged(object sender, EventArgs e)
  445. {
  446. panel_type_drs.Visible = true;
  447. }
  448.  
  449. private void radioButton_AOEHD_CheckedChanged(object sender, EventArgs e)
  450. {
  451. panel_type_drs.Visible = false;
  452. }
  453. }
  454. }
Add Comment
Please, Sign In to add comment