Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.79 KB | None | 0 0
  1. using System;
  2. using MySql.Data.MySqlClient;
  3. using System.Collections.Generic;
  4. using System.IO;
  5.  
  6. namespace MySqlTableCompare
  7. {
  8. public class fTable
  9. {
  10. public UInt32 ID;
  11. public UInt32[] KillCredit;
  12. public UInt32[] ModelID;
  13. public string IconName;
  14. public UInt32 Rank;
  15. public UInt32 Family;
  16. public UInt32 Type;
  17. public UInt32 TypeFlag;
  18. public UInt32 MovementID;
  19. public UInt32 HealthMod; //need convert to Float or double
  20. public UInt32 ManaMod; //need convert to Float or double
  21. public UInt32 RacialLider;
  22. public UInt32[] QuestItem;
  23.  
  24. public fTable()
  25. {
  26. KillCredit = new UInt32[2];
  27. ModelID = new UInt32[4];
  28. QuestItem = new UInt32[6];
  29. }
  30. };
  31.  
  32. public class sTable
  33. {
  34. public UInt32 ID;
  35. public UInt32[] KillCredit;
  36. public UInt32[] ModelID;
  37. public string IconName;
  38. public UInt32 Rank;
  39. public UInt32 Family;
  40. public UInt32 Type;
  41. public UInt32 TypeFlag;
  42. public UInt32 MovementID;
  43. public UInt32 HealthMod; //need convert to Float or double
  44. public UInt32 ManaMod; //need convert to Float or double
  45. public UInt32 RacialLider;
  46. public UInt32[] QuestItem;
  47.  
  48. public sTable()
  49. {
  50. KillCredit = new UInt32[2];
  51. ModelID = new UInt32[4];
  52. QuestItem = new UInt32[6];
  53. }
  54. };
  55.  
  56. public static class Program
  57. {
  58. const string connectionInfo = ("host=127.0.0.1;" + "port = '3306';" + "database='world';" + "UserName='root';" + "Password='mangos'");
  59. public static StreamWriter Log = new StreamWriter("sql_log.txt", true);
  60. public static MySqlCommand fcommand;
  61. public static MySqlCommand scommand;
  62. public static MySqlConnection connect = new MySqlConnection(connectionInfo);
  63.  
  64. public static List<fTable> fTables = new List<fTable>();
  65. public static List<sTable> sTables = new List<sTable>();
  66.  
  67. static void Main(string[] args)
  68. {
  69. Console.ForegroundColor = ConsoleColor.Yellow;
  70. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Programm is open!");
  71. ToLog("Programm is open!");
  72.  
  73. if (!TryCon())
  74. return;
  75.  
  76. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Get DB struct?");
  77. string variant = Console.ReadLine();
  78. if (variant == "y")
  79. {
  80. Console.WriteLine(">>Get DB struct...");
  81. ToLog(">>Get DB struct...");
  82. tGetStr();
  83. Console.WriteLine(">>Start compare...");
  84. ToLog(">>Start compare...");
  85. tCompare();
  86. }
  87. else if (variant == "n")
  88. {
  89. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Press any key for exit");
  90. connect.Close();
  91. }
  92. else
  93. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Neee press 'y' or 'n'");
  94.  
  95. Console.ReadKey();
  96. }
  97.  
  98. public static void ToLog(string text)
  99. {
  100. Log.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + text); Log.Flush();
  101. }
  102.  
  103. public static uint ToUInt32(this object val)
  104. {
  105. uint num;
  106. uint.TryParse(val.ToString(), out num);
  107. return num;
  108. }
  109.  
  110. public static void tGetStr()
  111. {
  112. connect.Close();
  113. connect.Open();
  114.  
  115. string fSelect = "SELECT * FROM world.creature_template";
  116. string sSelect = "SELECT * FROM world.creature_template1";
  117. fcommand = new MySqlCommand(fSelect, connect);
  118. scommand = new MySqlCommand(sSelect, connect);
  119. fTables.Clear();
  120. sTables.Clear();
  121.  
  122. using (var fDBstructur = fcommand.ExecuteReader())
  123. {
  124. while(fDBstructur.Read())
  125. {
  126. fTable table1 = new fTable();
  127.  
  128. table1.ID = fDBstructur[0].ToUInt32();
  129. table1.KillCredit[0] = fDBstructur[4].ToUInt32(); //kill credit 1,2
  130. table1.KillCredit[1] = fDBstructur[5].ToUInt32();
  131. table1.ModelID[0] = fDBstructur[6].ToUInt32(); //modelid1 id 1-4
  132. table1.ModelID[1] = fDBstructur[7].ToUInt32();
  133. table1.ModelID[2] = fDBstructur[8].ToUInt32();
  134. table1.ModelID[3] = fDBstructur[9].ToUInt32();
  135. table1.IconName = fDBstructur[12].ToString();
  136. table1.Rank = fDBstructur[23].ToUInt32(); //rank
  137. table1.Family = fDBstructur[34].ToUInt32(); //family
  138. table1.Type = fDBstructur[42].ToUInt32(); //type
  139. table1.TypeFlag = fDBstructur[43].ToUInt32();//type flag
  140. table1.MovementID = fDBstructur[66].ToUInt32(); //movement id
  141. table1.HealthMod = fDBstructur[68].ToUInt32(); //health mod
  142. table1.ManaMod = fDBstructur[69].ToUInt32(); //power(mana) mod
  143. table1.RacialLider = fDBstructur[71].ToUInt32(); //racial leader
  144. table1.QuestItem[0] = fDBstructur[72].ToUInt32(); //quest item 1-6
  145. table1.QuestItem[1] = fDBstructur[73].ToUInt32();
  146. table1.QuestItem[2] = fDBstructur[74].ToUInt32();
  147. table1.QuestItem[3] = fDBstructur[75].ToUInt32();
  148. table1.QuestItem[4] = fDBstructur[76].ToUInt32();
  149. table1.QuestItem[5] = fDBstructur[77].ToUInt32();
  150.  
  151. fTables.Add(table1);
  152. }
  153. }
  154. using (var sDBstructur = scommand.ExecuteReader())
  155. {
  156. while(sDBstructur.Read())
  157. {
  158. sTable table2 = new sTable();
  159.  
  160. table2.ID = sDBstructur[0].ToUInt32();
  161. table2.KillCredit[0] = sDBstructur[4].ToUInt32(); //kill credit 1,2
  162. table2.KillCredit[1] = sDBstructur[5].ToUInt32();
  163. table2.ModelID[0] = sDBstructur[6].ToUInt32(); //modelid1 id 1-4
  164. table2.ModelID[1] = sDBstructur[7].ToUInt32();
  165. table2.ModelID[2] = sDBstructur[8].ToUInt32();
  166. table2.ModelID[3] = sDBstructur[9].ToUInt32();
  167. table2.IconName = sDBstructur[12].ToString();
  168. table2.Rank = sDBstructur[23].ToUInt32(); //rank
  169. table2.Family = sDBstructur[34].ToUInt32(); //family
  170. table2.Type = sDBstructur[42].ToUInt32(); //type
  171. table2.TypeFlag = sDBstructur[43].ToUInt32();//type flag
  172. table2.MovementID = sDBstructur[66].ToUInt32(); //movement id
  173. table2.HealthMod = sDBstructur[68].ToUInt32(); //health mod
  174. table2.ManaMod = sDBstructur[69].ToUInt32(); //power(mana) mod
  175. table2.RacialLider = sDBstructur[71].ToUInt32(); //racial leader
  176. table2.QuestItem[0] = sDBstructur[72].ToUInt32(); //quest item 1-6
  177. table2.QuestItem[1] = sDBstructur[73].ToUInt32();
  178. table2.QuestItem[2] = sDBstructur[74].ToUInt32();
  179. table2.QuestItem[3] = sDBstructur[75].ToUInt32();
  180. table2.QuestItem[4] = sDBstructur[76].ToUInt32();
  181. table2.QuestItem[5] = sDBstructur[77].ToUInt32();
  182.  
  183. sTables.Add(table2);
  184. }
  185. }
  186. }
  187.  
  188. public static void tCompare()
  189. {
  190. int m = 0;
  191. string update = "update creature_template SET";
  192. for (int i = 0; i <= 5; ++i)
  193. {
  194. if (fTables[i].KillCredit[0] != sTables[i].KillCredit[0])
  195. Console.WriteLine("{0} KillCredit1 = {1} WHERE entry = {2};", update, sTables[i].KillCredit[0], fTables[i].ID);
  196.  
  197. if (fTables[i].KillCredit[1] != sTables[i].KillCredit[1])
  198. Console.WriteLine("{0} KillCredit2 = {1} WHERE entry = {2};", update, sTables[i].KillCredit[1], fTables[i].ID);
  199.  
  200. //model ID
  201. for (m = 0; m < 3; ++m);
  202. {
  203. string ModelID = "modelid1";
  204. switch (m)
  205. {
  206. case 0: ModelID = "modelid1"; break;
  207. case 1: ModelID = "modelid2"; break;
  208. case 2: ModelID = "modelid3"; break;
  209. }
  210. if(fTables[i].ModelID[m] != sTables[i].ModelID[m])
  211. Console.WriteLine("{0} {1} = {2} WHERE entry = {3}", update,ModelID,sTables[i].ModelID[m], fTables[i].ID);
  212. }
  213.  
  214. if (fTables[i].IconName != sTables[i].IconName)
  215. Console.WriteLine("{0} IconName = '{1}' WHERE entry = {2}", update, sTables[i].IconName, fTables[i].ID);
  216.  
  217. if (fTables[i].Rank != sTables[i].Rank)
  218. Console.WriteLine("{0} rank = {1} WHERE entry = {2}", update, sTables[i].Rank, fTables[i].ID);
  219.  
  220. /*if (fTables[i].ModelID[0] != sTables[i].ModelID[0])
  221. Console.WriteLine("{0} Modelid1 = {1} WHERE entry = {2}", update, sTables[i].ModelID[0], fTables[i].ID);
  222.  
  223. if (fTables[i].ModelID[0] != sTables[i].ModelID[0])
  224. Console.WriteLine("{0} Modelid1 = {1} WHERE entry = {2}", update, sTables[i].ModelID[0], fTables[i].ID);
  225.  
  226. if (fTables[i].ModelID[0] != sTables[i].ModelID[0])
  227. Console.WriteLine("{0} Modelid1 = {1} WHERE entry = {2}", update, sTables[i].ModelID[0], fTables[i].ID);
  228.  
  229. if (fTables[i].ModelID[0] != sTables[i].ModelID[0])
  230. Console.WriteLine("{0} Modelid1 = {1} WHERE entry = {2}", update, sTables[i].ModelID[0], fTables[i].ID);*/
  231. }
  232. }
  233.  
  234. public static bool TryCon()
  235. {
  236. try
  237. {
  238. MySqlConnection connect = new MySqlConnection(connectionInfo);
  239. connect.Open();
  240. connect.Close();
  241.  
  242. return true;
  243. }
  244. catch
  245. {
  246. Console.ForegroundColor = ConsoleColor.Red;
  247. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Check your MySQL server");
  248. ToLog("MySQL Server is not running");
  249.  
  250. return false;
  251. }
  252. }
  253. }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement