Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.67 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.Drawing.Imaging;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Diagnostics;
  12. using System.Threading;
  13. using System.Xml;
  14. using System.IO;
  15. using TAFactory.IconPack;
  16.  
  17.  
  18. namespace Game_s_Info
  19. {
  20. public partial class Form1 : Form
  21. {
  22.  
  23.  
  24. //SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  25. //saveFileDialog1.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*";
  26. XmlDocument document = new XmlDocument();
  27. int saves_button5, saves_game_button = 0;
  28. int button_5_position = 0;
  29. int size = 0;
  30. int button = 0;
  31. public Button[] mybutton = new Button[1000];
  32.  
  33.  
  34. public Form1()
  35. {
  36. InitializeComponent();
  37. if (File.Exists("saves.xml") == false)
  38. {
  39. XmlTextWriter textWritter = new XmlTextWriter("saves.xml", Encoding.UTF8);
  40. textWritter.WriteStartDocument();
  41. textWritter.WriteStartElement("head");
  42. textWritter.WriteEndElement();
  43. textWritter.Close();
  44.  
  45. document.Load("saves.xml");
  46. XmlNode save_check = document.CreateElement("save_check");
  47. document.DocumentElement.AppendChild(save_check); // указываем родителя
  48. XmlAttribute button5_check = document.CreateAttribute("button5_check");
  49. XmlAttribute game_button_check = document.CreateAttribute("game_button_check");
  50. XmlAttribute game_button_value = document.CreateAttribute("game_button_value");
  51. XmlAttribute screen_size_x = document.CreateAttribute("screen_size_x");
  52. XmlAttribute screen_size_y = document.CreateAttribute("screen_size_y");
  53.  
  54.  
  55. button5_check.Value = Convert.ToString(saves_button5);// устанавливаем значение атрибута
  56. game_button_check.Value = Convert.ToString(saves_game_button);
  57. game_button_value.Value = Convert.ToString(button);
  58. screen_size_x.Value = "0";
  59. screen_size_y.Value = "0";
  60.  
  61.  
  62.  
  63. save_check.Attributes.Append(button5_check);
  64. save_check.Attributes.Append(game_button_check);// добавляем атрибут
  65. save_check.Attributes.Append(game_button_value);
  66. save_check.Attributes.Append(screen_size_x);
  67. save_check.Attributes.Append(screen_size_y);
  68. document.Save("saves.xml");
  69. }
  70. else
  71. {
  72. XmlReader read = XmlReader.Create("saves.xml");
  73. read.ReadToFollowing("save_check");
  74. saves_button5 = Convert.ToInt32(read.GetAttribute("button5_check"));
  75. saves_game_button = Convert.ToInt32(read.GetAttribute("game_button_check"));
  76. button = Convert.ToInt32(read.GetAttribute("game_button_value"));
  77. //this.SizeFromClientSize(new Size(Convert.ToInt32(read.GetAttribute("screen_size_x")), Convert.ToInt32(read.GetAttribute("screen_size_y"))));
  78. this.SizeFromClientSize(new Size(2000, 5000));
  79. if (button < 20)
  80. {
  81. this.SetAutoScrollMargin(0, 800);
  82. }
  83. else
  84. {
  85. this.SetAutoScrollMargin(0, button * 40);
  86. }
  87. read.Close();
  88. }
  89.  
  90. if (saves_button5 == 1)
  91. {
  92. XmlReader reader = XmlReader.Create("saves.xml");
  93. reader.ReadToFollowing("button5");
  94. button5.Location = new Point(Convert.ToInt32(reader.GetAttribute("x")), Convert.ToInt32(reader.GetAttribute("y")));
  95. button_5_position = Convert.ToInt32(reader.GetAttribute("button5_position"));
  96. reader.Close();
  97. button5.ContextMenuStrip = contextMenuStrip1;
  98. this.Controls.Add(button5);
  99. }
  100. // создаем элементы меню
  101. ToolStripMenuItem changeName = new ToolStripMenuItem("Изменить название");
  102. ToolStripMenuItem changeIcon = new ToolStripMenuItem("Изменить ярлык");
  103. ToolStripMenuItem addGameWithOtherIcon = new ToolStripMenuItem("Добавить игру с другим ярлыком");
  104. ToolStripMenuItem deleteGame = new ToolStripMenuItem("Удалить игру");
  105. // добавляем элементы в меню
  106. contextMenuStrip1.Items.AddRange(new[] { changeName, changeIcon, addGameWithOtherIcon, deleteGame });
  107. // ассоциируем контекстное меню с текстовым полем
  108. // устанавливаем обработчики событий для меню
  109. changeName.Click += changeName_Click;
  110. changeIcon.Click += changeIcon_Click;
  111. addGameWithOtherIcon.Click += addGameWithOtherIconClick;
  112. deleteGame.Click += deleteGame_Click; ;
  113. if (saves_game_button != 0)
  114. {
  115.  
  116.  
  117. for (int i = 1; i < button + 1; i++)
  118. {
  119. XmlReader reader = XmlReader.Create("saves.xml");
  120. reader.ReadToFollowing("mbutton" + i);
  121.  
  122. form2[i] = new Form2();
  123. mybutton[i] = new Button();
  124. mybutton[i].Location = new Point(Convert.ToInt32(reader.GetAttribute("x")), Convert.ToInt32(reader.GetAttribute("y")));
  125. mybutton[i].Name = "mbutton" + Convert.ToString(i);
  126. mybutton[i].Text = reader.GetAttribute("game");
  127. mybutton[i].Click += new EventHandler(form2[i].ShowForm2);
  128. mybutton[i].Size = new Size(200, 200);
  129. mybutton[i].TextAlign = ContentAlignment.BottomCenter;
  130. //mybutton[i].BackgroundImage = Image.FromFile("1.png");
  131.  
  132.  
  133. //if (reader.GetAttribute("textBox5") == "Пройдено")
  134. //{
  135. // mybutton[i].BackColor = Color.FromArgb(143, 255, 84);
  136. //}
  137. //else if (reader.GetAttribute("textBox5") == "На паузе")
  138. //{
  139. // mybutton[i].BackColor = Color.FromArgb(255, 212, 71);
  140. //}
  141. //else if (reader.GetAttribute("textBox5") == "Бросил")
  142. //{
  143. // mybutton[i].BackColor = Color.FromArgb(255, 120, 86);
  144. //}
  145. //else if (reader.GetAttribute("textBox5") == "Играю")
  146. //{
  147. // mybutton[i].BackColor = Color.FromArgb(76, 153, 255);
  148. //}
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. if (reader.GetAttribute("icon").Substring(0,1) == "t")
  156. {
  157. mybutton[i].ImageAlign = ContentAlignment.TopCenter;
  158. }
  159. else
  160. {
  161. mybutton[i].ImageAlign = ContentAlignment.MiddleCenter;
  162. }
  163. mybutton[i].ContextMenuStrip = contextMenuStrip1;
  164.  
  165.  
  166.  
  167. if (mybutton[i].Text.Length > 37)
  168. {
  169. mybutton[i].Font = new Font(mybutton[i].Font.Name, 9, FontStyle.Bold);
  170. }
  171. else
  172. {
  173. mybutton[i].Font = new Font(mybutton[i].Font.Name, 10, FontStyle.Bold);
  174. }
  175.  
  176. byte[] bmpData;
  177. bmpData = Convert.FromBase64String(reader.GetAttribute("icon").Remove(0,1));
  178. MemoryStream stream = new MemoryStream(bmpData);
  179. mybutton[i].Image = new Bitmap(stream);
  180. reader.Close();
  181. this.Controls.Add(mybutton[i]);
  182. GC.WaitForPendingFinalizers();
  183. GC.Collect();
  184. }
  185. }
  186.  
  187. }
  188. void deleteGame_Click(object sender, EventArgs e)
  189. {
  190. XmlReader reader = XmlReader.Create("saves.xml");
  191. reader.ReadToFollowing("save_check");
  192. int current_number = Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7));
  193. int number_games = Convert.ToInt32(reader.GetAttribute("game_button_value")) - Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7));
  194. reader.ReadToFollowing("button5");
  195. int x = Convert.ToInt32(reader.GetAttribute("x"));
  196. int y = Convert.ToInt32(reader.GetAttribute("y"));
  197. reader.Close();
  198. for (int i = 0; i < number_games; i++)
  199. {
  200. XmlReader readerr = XmlReader.Create("saves.xml");
  201. readerr.ReadToFollowing("mbutton" + (current_number + i + 1));
  202. string game = readerr.GetAttribute("game");
  203. string game_patch = readerr.GetAttribute("game_patch");
  204. string icon_patch = readerr.GetAttribute("icon_patch");
  205. string time = readerr.GetAttribute("time");
  206. string info = readerr.GetAttribute("info");
  207. string icon = readerr.GetAttribute("icon");
  208. string label7 = readerr.GetAttribute("label7");
  209. string textBox1 = readerr.GetAttribute("textBox1");
  210. string textBox2 = readerr.GetAttribute("textBox2");
  211. string textBox3 = readerr.GetAttribute("textBox3");
  212. string textBox4 = readerr.GetAttribute("textBox4");
  213. string textBox5 = readerr.GetAttribute("textBox5");
  214. string textBox7 = readerr.GetAttribute("textBox7");
  215. mybutton[current_number + i].Text = game;
  216. if (icon.Substring(0, 1) == "t")
  217. {
  218. mybutton[current_number + i].ImageAlign = ContentAlignment.TopCenter;
  219. }
  220. else
  221. {
  222. mybutton[current_number + i].ImageAlign = ContentAlignment.MiddleCenter;
  223. }
  224. byte[] bmpData;
  225. bmpData = Convert.FromBase64String(icon.Remove(0, 1));
  226. MemoryStream stream = new MemoryStream(bmpData);
  227. mybutton[current_number + i].Image = new Bitmap(stream);
  228. readerr.Close();
  229.  
  230. document.Load("saves.xml");
  231. //XmlNodeList xmlNode = document.GetElementsByTagName("mbutton2");
  232. //xmlNode.Attributes[0]
  233. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("game", game);
  234. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("game_patch", game_patch);
  235. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("icon_patch", icon_patch);
  236. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("time", time);
  237. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("info", info);
  238. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("icon", icon);
  239. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("label7", label7);
  240. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox1", textBox1);
  241. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox2", textBox2);
  242. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox3", textBox3);
  243. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox4", textBox4);
  244. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox5", textBox5);
  245. document.DocumentElement["mbutton" + (current_number + i)].SetAttribute("textBox7", textBox7);
  246. document.Save("saves.xml");
  247. }
  248. button = button - 1;
  249. document.Load("saves.xml");
  250. document.DocumentElement["save_check"].SetAttribute("game_button_value", Convert.ToString(button));
  251. if (button_5_position == 0)
  252. {
  253. button_5_position = 5;
  254. document.DocumentElement["button5"].SetAttribute("x", "1003");
  255. document.DocumentElement["button5"].SetAttribute("y", Convert.ToString(y - 200));
  256. button5.Location = new Point(1003, y - 200);
  257. }
  258. else
  259. {
  260. button_5_position = button_5_position - 1;
  261. document.DocumentElement["button5"].SetAttribute("x", Convert.ToString(x - 200));
  262. button5.Location = new Point(x - 200, y);
  263. }
  264. document.DocumentElement["button5"].SetAttribute("button5_position", Convert.ToString(button_5_position));
  265. XmlNode xmlNode = document.GetElementsByTagName("mbutton" + (current_number + number_games))[0];
  266. xmlNode.ParentNode.RemoveChild(xmlNode);
  267. document.Save("saves.xml");
  268. mybutton[current_number + number_games].Dispose();
  269. }
  270.  
  271. void changeIcon_Click(object sender, EventArgs e)
  272. {
  273. OpenFileDialog openFileDialog12 = new OpenFileDialog();
  274. // выход, если была нажата кнопка Отмена и прочие (кроме ОК)
  275. if (openFileDialog12.ShowDialog() != DialogResult.OK) return;
  276. // всё. имя файла теперь хранится в openFileDialog1.FileName
  277.  
  278. Bitmap bitmap;
  279.  
  280. string file_extension = openFileDialog12.FileName.Substring(openFileDialog12.FileName.LastIndexOf('.'));
  281. string position = "t";
  282. if (file_extension == ".exe" || file_extension == ".dll")
  283. {
  284. int x = 0;
  285. int folder = 0;
  286. int icon = 0;
  287.  
  288. List<Icon> shellIcons = IconHelper.ExtractAllIcons(openFileDialog12.FileName);
  289. List<Icon> openFolderSet = IconHelper.SplitGroupIcon(shellIcons[0]);
  290.  
  291. for (int i = 0; i < shellIcons.Count; i++)
  292. {
  293. int n = 0;
  294. for (int j = 0; j < openFolderSet.Count; j++)
  295. {
  296. if (openFolderSet[j].Height > x)
  297. {
  298. x = openFolderSet[j].Height;
  299. folder = i;
  300. icon = j;
  301. }
  302. }
  303. if (shellIcons.Count - 1 > n)
  304. {
  305. n++;
  306. openFolderSet = IconHelper.SplitGroupIcon(shellIcons[n]);
  307. }
  308. }
  309. openFolderSet = IconHelper.SplitGroupIcon(shellIcons[folder]);
  310. bitmap = new Bitmap(openFolderSet[icon].ToBitmap(), 160, 160);
  311. mybutton[Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7))].Image = bitmap;
  312. }
  313. else
  314. {
  315. Bitmap test = new Bitmap(openFileDialog12.FileName);
  316. double x = test.Width;
  317. double y = test.Height;
  318. if (x > y)
  319. {
  320. double z = x / 160;
  321. x = x / z;
  322. y = y / z;
  323. mybutton[Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7))].ImageAlign = ContentAlignment.MiddleCenter;
  324. position = "c";
  325. }
  326. else
  327. {
  328. double z = y / 160;
  329. x = x / z;
  330. y = y / z;
  331. position = "t";
  332. }
  333. bitmap = new Bitmap(new Bitmap(openFileDialog12.FileName), Convert.ToInt32(x), Convert.ToInt32(y));
  334. mybutton[Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7))].Image = bitmap;
  335. }
  336.  
  337. TypeConverter bmpConverter = TypeDescriptor.GetConverter(bitmap.GetType());
  338. byte[] bmpData = (byte[])bmpConverter.ConvertTo(bitmap, typeof(byte[]));
  339. string bmp_str = Convert.ToBase64String(bmpData, Base64FormattingOptions.InsertLineBreaks);
  340.  
  341. document.Load("saves.xml");
  342. document.DocumentElement[contextMenuStrip1.SourceControl.Name].SetAttribute("icon", position + bmp_str);
  343. document.Save("saves.xml");
  344.  
  345. GC.WaitForPendingFinalizers();
  346. GC.Collect();
  347. }
  348. void changeName_Click(object sender, EventArgs e)
  349. {
  350. Form4 form4 = new Form4() {a = contextMenuStrip1.SourceControl.Name };
  351. form4.textBox1.Text = contextMenuStrip1.SourceControl.Text;
  352. form4.ShowDialog();
  353. XmlReader reader = XmlReader.Create("saves.xml");
  354. reader.ReadToFollowing(contextMenuStrip1.SourceControl.Name);
  355. contextMenuStrip1.SourceControl.Text = reader.GetAttribute("game");
  356. if (contextMenuStrip1.SourceControl.Text.Length > 37)
  357. {
  358. contextMenuStrip1.SourceControl.Font = new Font(contextMenuStrip1.SourceControl.Font.Name, 9, System.Drawing.FontStyle.Bold);
  359. }
  360. else
  361. {
  362. contextMenuStrip1.SourceControl.Font = new Font(contextMenuStrip1.SourceControl.Font.Name, 10, System.Drawing.FontStyle.Bold);
  363. }
  364. reader.Close();
  365.  
  366. }
  367.  
  368. void addGameWithOtherIconClick(object sender, EventArgs e)
  369. {
  370. if (saves_button5 == 0)
  371. {
  372. document.Load("saves.xml");
  373.  
  374. XmlNode button5_saves = document.CreateElement("button5");
  375. document.DocumentElement.AppendChild(button5_saves); // указываем родителя
  376. XmlAttribute button5_x = document.CreateAttribute("x"); // создаём атрибут
  377. XmlAttribute button5_y = document.CreateAttribute("y");
  378. XmlAttribute button5_position = document.CreateAttribute("button5_position");
  379. button5_x.Value = Convert.ToString(button5.Location.X);
  380. button5_y.Value = Convert.ToString(button5.Location.Y);// устанавливаем значение атрибута
  381. button5_position.Value = Convert.ToString(button_5_position);
  382. button5_saves.Attributes.Append(button5_x);
  383. button5_saves.Attributes.Append(button5_y);// добавляем атрибут
  384. button5_saves.Attributes.Append(button5_position);
  385. document.Save("saves.xml");
  386.  
  387. saves_button5 = 1;
  388. document.Load("saves.xml");
  389. document.DocumentElement["save_check"].SetAttribute("button5_check", Convert.ToString(saves_button5));
  390. document.Save("saves.xml");
  391. }
  392.  
  393. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  394. // выход, если была нажата кнопка Отмена и прочие (кроме ОК)
  395. if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
  396. // всё. имя файла теперь хранится в openFileDialog1.FileName
  397.  
  398. button = button + 1;
  399. form2[button] = new Form2();
  400. mybutton[button] = new Button();
  401. mybutton[button].Location = new Point(button5.Location.X, button5.Location.Y);
  402. mybutton[button].Text = openFileDialog1.SafeFileName.Remove(openFileDialog1.SafeFileName.LastIndexOf('.'));
  403. mybutton[button].Name = "mbutton" + Convert.ToString(button);
  404. mybutton[button].Click += new EventHandler(form2[button].ShowForm2);
  405. mybutton[button].Size = new Size(200, 200);
  406. mybutton[button].ContextMenuStrip = contextMenuStrip1;
  407. if (mybutton[button].Text.Length > 37)
  408. {
  409. mybutton[button].Font = new Font(mybutton[button].Font.Name, 9, System.Drawing.FontStyle.Bold);
  410. }
  411. else
  412. {
  413. mybutton[button].Font = new Font(mybutton[button].Font.Name, 10, System.Drawing.FontStyle.Bold);
  414. }
  415. mybutton[button].TextAlign = ContentAlignment.BottomCenter;
  416. mybutton[button].ImageAlign = ContentAlignment.TopCenter;
  417.  
  418. OpenFileDialog openFileDialog12 = new OpenFileDialog();
  419. // выход, если была нажата кнопка Отмена и прочие (кроме ОК)
  420. if (openFileDialog12.ShowDialog() != DialogResult.OK) return;
  421. // всё. имя файла теперь хранится в openFileDialog1.FileName
  422.  
  423. Bitmap bitmap;
  424. string position = "t";
  425. string file_extension = openFileDialog12.FileName.Substring(openFileDialog12.FileName.LastIndexOf('.'));
  426.  
  427. if (file_extension == ".exe" || file_extension == ".dll")
  428. {
  429. int x = 0;
  430. int folder = 0;
  431. int icon = 0;
  432.  
  433. List<Icon> shellIcons = IconHelper.ExtractAllIcons(openFileDialog12.FileName);
  434. List<Icon> openFolderSet = IconHelper.SplitGroupIcon(shellIcons[0]);
  435.  
  436. for (int i = 0; i < shellIcons.Count; i++)
  437. {
  438. int n = 0;
  439. for (int j = 0; j < openFolderSet.Count; j++)
  440. {
  441. if (openFolderSet[j].Height > x)
  442. {
  443. x = openFolderSet[j].Height;
  444. folder = i;
  445. icon = j;
  446. }
  447. }
  448. if (shellIcons.Count - 1 > n)
  449. {
  450. n++;
  451. openFolderSet = IconHelper.SplitGroupIcon(shellIcons[n]);
  452. }
  453. }
  454. openFolderSet = IconHelper.SplitGroupIcon(shellIcons[folder]);
  455. bitmap = new Bitmap(openFolderSet[icon].ToBitmap(), 160, 160);
  456. mybutton[button].Image = bitmap;
  457. }
  458. else
  459. {
  460. Bitmap test = new Bitmap(openFileDialog12.FileName);
  461. double x = test.Width;
  462. double y = test.Height;
  463. if (x > y)
  464. {
  465. double z = x / 160;
  466. x = x / z;
  467. y = y / z;
  468. mybutton[Convert.ToInt32(contextMenuStrip1.SourceControl.Name.Remove(0, 7))].ImageAlign = ContentAlignment.MiddleCenter;
  469. position = "c";
  470. }
  471. else
  472. {
  473. double z = y / 160;
  474. x = x / z;
  475. y = y / z;
  476. position = "t";
  477. }
  478. bitmap = new Bitmap(new Bitmap(openFileDialog12.FileName), Convert.ToInt32(x), Convert.ToInt32(y));
  479. mybutton[button].Image = bitmap;
  480. }
  481.  
  482. TypeConverter bmpConverter = TypeDescriptor.GetConverter(bitmap.GetType());
  483. byte[] bmpData = (byte[])bmpConverter.ConvertTo(bitmap, typeof(byte[]));
  484. string bmp_str = Convert.ToBase64String(bmpData, Base64FormattingOptions.InsertLineBreaks);
  485. this.Controls.Add(mybutton[button]);
  486.  
  487. document.Load("saves.xml");
  488. XmlNode game_button_saves = document.CreateElement(mybutton[button].Name);
  489. document.DocumentElement.AppendChild(game_button_saves); // указываем родителя
  490. XmlAttribute game_button_x = document.CreateAttribute("x"); // создаём атрибут
  491. XmlAttribute game_button_y = document.CreateAttribute("y");
  492. XmlAttribute game = document.CreateAttribute("game");
  493. XmlAttribute game_patch = document.CreateAttribute("game_patch");
  494. XmlAttribute icon_patch = document.CreateAttribute("icon_patch");
  495. XmlAttribute time = document.CreateAttribute("time");
  496. XmlAttribute ico = document.CreateAttribute("icon");
  497. XmlAttribute label7 = document.CreateAttribute("label7");
  498. XmlAttribute textBox1 = document.CreateAttribute("textBox1");
  499. XmlAttribute textBox2 = document.CreateAttribute("textBox2");
  500. XmlAttribute textBox3 = document.CreateAttribute("textBox3");
  501. XmlAttribute textBox4 = document.CreateAttribute("textBox4");
  502. XmlAttribute textBox5 = document.CreateAttribute("textBox5");
  503. XmlAttribute textBox7 = document.CreateAttribute("textBox7");
  504. label7.Value = "";
  505. textBox1.Value = "";
  506. textBox2.Value = "";
  507. textBox3.Value = "";
  508. textBox4.Value = "";
  509. textBox5.Value = "";
  510. textBox7.Value = "";
  511. ico.Value = position + bmp_str;
  512. game_button_x.Value = Convert.ToString(mybutton[button].Location.X);
  513. game_button_y.Value = Convert.ToString(mybutton[button].Location.Y);// устанавливаем значение атрибута
  514. game_patch.Value = openFileDialog1.FileName;
  515. icon_patch.Value = openFileDialog12.FileName;
  516. time.Value = "00.00.00";
  517. game.Value = mybutton[button].Text;
  518. game_button_saves.Attributes.Append(game_button_x);
  519. game_button_saves.Attributes.Append(game_button_y);// добавляем атрибут
  520. game_button_saves.Attributes.Append(game);
  521. game_button_saves.Attributes.Append(game_patch);
  522. game_button_saves.Attributes.Append(icon_patch);
  523. game_button_saves.Attributes.Append(time);
  524. game_button_saves.Attributes.Append(ico);
  525. game_button_saves.Attributes.Append(label7);
  526. game_button_saves.Attributes.Append(textBox1);
  527. game_button_saves.Attributes.Append(textBox2);
  528. game_button_saves.Attributes.Append(textBox3);
  529. game_button_saves.Attributes.Append(textBox4);
  530. game_button_saves.Attributes.Append(textBox5);
  531. game_button_saves.Attributes.Append(textBox7);
  532. document.DocumentElement["save_check"].SetAttribute("game_button_value", Convert.ToString(button));
  533.  
  534.  
  535.  
  536.  
  537. if (saves_game_button == 0)
  538. {
  539. document.DocumentElement["save_check"].SetAttribute("game_button_check", "1");
  540. }
  541.  
  542.  
  543. document.Save("saves.xml");
  544.  
  545.  
  546.  
  547. if (button_5_position > 4)
  548. {
  549. button5.Location = new Point(mybutton[1].Location.X, button5.Location.Y + 200);
  550. button_5_position = 0;
  551. }
  552. else
  553. {
  554. button5.Location = new Point(button5.Location.X + 200, button5.Location.Y);
  555. button_5_position = button_5_position + 1;
  556. }
  557. this.Controls.Add(button5);
  558. document.Load("saves.xml");
  559. document.DocumentElement["button5"].SetAttribute("x", Convert.ToString(button5.Location.X));
  560. document.DocumentElement["button5"].SetAttribute("y", Convert.ToString(button5.Location.Y));
  561. document.DocumentElement["button5"].SetAttribute("button5_position", Convert.ToString(button_5_position));
  562. document.Save("saves.xml");
  563. if (size == 89)
  564. {
  565. this.Width = 1161;
  566. }
  567. size++;
  568.  
  569. GC.WaitForPendingFinalizers();
  570. GC.Collect();
  571. }
  572.  
  573.  
  574.  
  575.  
  576.  
  577. Form2 d = new Form2();
  578. Form2[] form2 = new Form2[1000];
  579.  
  580. private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  581. {
  582.  
  583. }
  584.  
  585. private void button1_Click(object sender, EventArgs e)
  586. {
  587. //button1.Visible = false;
  588. int x = 3;
  589. int y = 0;
  590. mybutton[3].Visible = false;
  591. mybutton[4].Visible = false;
  592. mybutton[6].Visible = false;
  593. XmlReader reader = XmlReader.Create("saves.xml");
  594. reader.ReadToFollowing("save_check");
  595. for (int i = 1; i < Convert.ToInt32(reader.GetAttribute("game_button_value")) + 1; i++)
  596. {
  597. if (mybutton[i].Visible == true)
  598. {
  599. mybutton[i].Location = new Point(x, y);
  600. x = x + 200;
  601. }
  602. }
  603. reader.Close();
  604. }
  605.  
  606. private void button2_Click(object sender, EventArgs e)
  607. {
  608. int x = 3;
  609. int y = 0;
  610. XmlReader reader = XmlReader.Create("saves.xml");
  611. reader.ReadToFollowing("save_check");
  612. for (int i = 1; i < Convert.ToInt32(reader.GetAttribute("game_button_value")) + 1; i++)
  613. {
  614. mybutton[i].Visible = true;
  615. mybutton[i].Location = new Point(x, y);
  616. if (x == 1003)
  617. {
  618. x = 3;
  619. y = y + 200;
  620. }
  621. else
  622. {
  623. x = x + 200;
  624. }
  625.  
  626.  
  627. }
  628. reader.Close();
  629. }
  630.  
  631. private void button5_Click(object sender, EventArgs e)
  632. {
  633. if (saves_button5 == 0)
  634. {
  635. document.Load("saves.xml");
  636.  
  637. XmlNode button5_saves = document.CreateElement("button5");
  638. document.DocumentElement.AppendChild(button5_saves); // указываем родителя
  639. XmlAttribute button5_x = document.CreateAttribute("x"); // создаём атрибут
  640. XmlAttribute button5_y = document.CreateAttribute("y");
  641. XmlAttribute button5_position = document.CreateAttribute("button5_position");
  642. button5_x.Value = Convert.ToString(button5.Location.X);
  643. button5_y.Value = Convert.ToString(button5.Location.Y);// устанавливаем значение атрибута
  644. button5_position.Value = Convert.ToString(button_5_position);
  645. button5_saves.Attributes.Append(button5_x);
  646. button5_saves.Attributes.Append(button5_y);// добавляем атрибут
  647. button5_saves.Attributes.Append(button5_position);
  648. document.Save("saves.xml");
  649.  
  650. saves_button5 = 1;
  651. document.Load("saves.xml");
  652. document.DocumentElement["save_check"].SetAttribute("button5_check", Convert.ToString(saves_button5));
  653. document.Save("saves.xml");
  654. }
  655.  
  656. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  657. // выход, если была нажата кнопка Отмена и прочие (кроме ОК)
  658. if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
  659. // всё. имя файла теперь хранится в openFileDialog1.FileName
  660.  
  661. button = button + 1;
  662. form2[button] = new Form2();
  663. mybutton[button] = new Button();
  664. mybutton[button].Location = new Point(button5.Location.X, button5.Location.Y);
  665. mybutton[button].Text = openFileDialog1.SafeFileName.Remove(openFileDialog1.SafeFileName.LastIndexOf('.'));
  666. mybutton[button].Name = "mbutton" + Convert.ToString(button);
  667. mybutton[button].Click += new EventHandler(form2[button].ShowForm2);
  668. mybutton[button].Size = new Size(200, 200);
  669. mybutton[button].ContextMenuStrip = contextMenuStrip1;
  670. if (mybutton[button].Text.Length > 37)
  671. {
  672. mybutton[button].Font = new Font(mybutton[button].Font.Name, 9, System.Drawing.FontStyle.Bold);
  673. }
  674. else
  675. {
  676. mybutton[button].Font = new Font(mybutton[button].Font.Name, 10, System.Drawing.FontStyle.Bold);
  677. }
  678. mybutton[button].TextAlign = ContentAlignment.BottomCenter;
  679. mybutton[button].ImageAlign = ContentAlignment.TopCenter;
  680.  
  681. int x = 0;
  682. int folder = 0;
  683. int icon = 0;
  684.  
  685. List<Icon> shellIcons = IconHelper.ExtractAllIcons(openFileDialog1.FileName);
  686. List<Icon> openFolderSet = IconHelper.SplitGroupIcon(shellIcons[0]);
  687.  
  688. for (int i = 0; i < shellIcons.Count; i++)
  689. {
  690. int n = 0;
  691. for (int j = 0; j < openFolderSet.Count; j++)
  692. {
  693. if (openFolderSet[j].Height > x)
  694. {
  695. x = openFolderSet[j].Height;
  696. folder = i;
  697. icon = j;
  698. }
  699. }
  700. if (shellIcons.Count - 1 > n)
  701. {
  702. n++;
  703. openFolderSet = IconHelper.SplitGroupIcon(shellIcons[n]);
  704. }
  705. }
  706. openFolderSet = IconHelper.SplitGroupIcon(shellIcons[folder]);
  707. Bitmap bitmap = new Bitmap(openFolderSet[icon].ToBitmap(), 160, 160);
  708. mybutton[button].Image = bitmap;
  709. this.Controls.Add(mybutton[button]);
  710.  
  711. TypeConverter bmpConverter = TypeDescriptor.GetConverter(bitmap.GetType());
  712. byte[] bmpData = (byte[])bmpConverter.ConvertTo(bitmap, typeof(byte[]));
  713. string bmp_str = "t" + Convert.ToBase64String(bmpData, Base64FormattingOptions.InsertLineBreaks);
  714.  
  715.  
  716.  
  717. document.Load("saves.xml");
  718. XmlNode game_button_saves = document.CreateElement(mybutton[button].Name);
  719. document.DocumentElement.AppendChild(game_button_saves); // указываем родителя
  720. XmlAttribute game_button_x = document.CreateAttribute("x"); // создаём атрибут
  721. XmlAttribute game_button_y = document.CreateAttribute("y");
  722. XmlAttribute game = document.CreateAttribute("game");
  723. XmlAttribute info = document.CreateAttribute("info");
  724. XmlAttribute label7 = document.CreateAttribute("label7");
  725. XmlAttribute textBox1 = document.CreateAttribute("textBox1");
  726. XmlAttribute textBox2 = document.CreateAttribute("textBox2");
  727. XmlAttribute textBox3 = document.CreateAttribute("textBox3");
  728. XmlAttribute textBox4 = document.CreateAttribute("textBox4");
  729. XmlAttribute textBox5 = document.CreateAttribute("textBox5");
  730. XmlAttribute textBox7 = document.CreateAttribute("textBox7");
  731. XmlAttribute game_patch = document.CreateAttribute("game_patch");
  732. XmlAttribute icon_patch = document.CreateAttribute("icon_patch");
  733. XmlAttribute time = document.CreateAttribute("time");
  734. XmlAttribute ico = document.CreateAttribute("icon");
  735. ico.Value = bmp_str;/*Convert.ToString(folder) + Convert.ToString(icon);*/
  736. info.Value = "";
  737. game_button_x.Value = Convert.ToString(mybutton[button].Location.X);
  738. game_button_y.Value = Convert.ToString(mybutton[button].Location.Y);// устанавливаем значение атрибута
  739. game_patch.Value = openFileDialog1.FileName;
  740. icon_patch.Value = openFileDialog1.FileName;
  741. label7.Value = "";
  742. textBox1.Value = "";
  743. textBox2.Value = "";
  744. textBox3.Value = "";
  745. textBox4.Value = "";
  746. textBox5.Value = "";
  747. textBox7.Value = "";
  748. time.Value = "00.00.00";
  749. game.Value = mybutton[button].Text;
  750. game_button_saves.Attributes.Append(game_button_x);
  751. game_button_saves.Attributes.Append(game_button_y);// добавляем атрибут
  752. game_button_saves.Attributes.Append(game);
  753. game_button_saves.Attributes.Append(game_patch);
  754. game_button_saves.Attributes.Append(icon_patch);
  755. game_button_saves.Attributes.Append(time);
  756. game_button_saves.Attributes.Append(info);
  757. game_button_saves.Attributes.Append(ico);
  758. game_button_saves.Attributes.Append(label7);
  759. game_button_saves.Attributes.Append(textBox1);
  760. game_button_saves.Attributes.Append(textBox2);
  761. game_button_saves.Attributes.Append(textBox3);
  762. game_button_saves.Attributes.Append(textBox4);
  763. game_button_saves.Attributes.Append(textBox5);
  764. game_button_saves.Attributes.Append(textBox7);
  765. document.DocumentElement["save_check"].SetAttribute("game_button_value", Convert.ToString(button));
  766.  
  767.  
  768.  
  769.  
  770. if (saves_game_button == 0)
  771. {
  772. document.DocumentElement["save_check"].SetAttribute("game_button_check", "1");
  773. }
  774.  
  775.  
  776. document.Save("saves.xml");
  777.  
  778.  
  779.  
  780. if (button_5_position > 4)
  781. {
  782. button5.Location = new Point(mybutton[1].Location.X, button5.Location.Y + 200);
  783. button_5_position = 0;
  784. }
  785. else
  786. {
  787. button5.Location = new Point(button5.Location.X + 200, button5.Location.Y);
  788. button_5_position = button_5_position + 1;
  789. }
  790. this.Controls.Add(button5);
  791. document.Load("saves.xml");
  792. document.DocumentElement["button5"].SetAttribute("x", Convert.ToString(button5.Location.X));
  793. document.DocumentElement["button5"].SetAttribute("y", Convert.ToString(button5.Location.Y));
  794. document.DocumentElement["button5"].SetAttribute("button5_position", Convert.ToString(button_5_position));
  795.  
  796. document.DocumentElement["save_check"].SetAttribute("screen_size_x", Convert.ToString(AutoScrollMargin.Width));
  797. document.DocumentElement["save_check"].SetAttribute("screen_size_y", Convert.ToString(AutoScrollMargin.Width));
  798.  
  799. document.Save("saves.xml");
  800. size++;
  801.  
  802. GC.WaitForPendingFinalizers();
  803. GC.Collect();
  804. }
  805.  
  806.  
  807.  
  808.  
  809. }
  810. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement