Advertisement
Guest User

Untitled

a guest
Oct 27th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.91 KB | None | 0 0
  1. public class ObjectSaverLoader
  2. {
  3. string ObFolder;
  4. public string SaveName;
  5. public string FileName;
  6. List<string> Output = new List<string>();
  7. public ObjectSaverLoader(string objectfolder, string savename, string filename)
  8. {
  9. SaveName = savename;
  10. ObFolder = objectfolder;
  11. // Output = "";
  12. FileName = filename;
  13. }
  14. public string GetValue(string valname)
  15. {
  16. foreach (string v in Output)
  17. {
  18. string[] x = v.Split(':');
  19. if (x.GetUpperBound(0) > 0)
  20. {
  21. if (x[0].ToLower() == valname.ToLower())
  22. {
  23. return x[1].Replace("(nll)", Environment.NewLine);
  24. }
  25. }
  26. }
  27.  
  28. return null;
  29. }
  30. public List<string> GetValueStrLst(string valname)
  31. {
  32. List<string> ret = new List<string>();
  33.  
  34. foreach (string v in Output)
  35. {
  36. string[] x = v.Split(':');
  37. if (x.GetUpperBound(0) > 0)
  38. {
  39. if (x[0].ToLower() == valname.ToLower())
  40. {
  41. ret.Add(x[1]);
  42. }
  43. }
  44. }
  45.  
  46. return ret;
  47. }
  48. public int GetValueInt(string valname)
  49. {
  50. foreach (string v in Output)
  51. {
  52. string[] x = v.Split(':');
  53. if (x.GetUpperBound(0) > 0)
  54. {
  55. if (x[0].ToLower() == valname.ToLower())
  56. {
  57. try
  58. {
  59.  
  60. return Convert.ToInt32(x[1]);
  61. }
  62. catch
  63. {
  64. return -1;
  65. }
  66. }
  67. }
  68. }
  69.  
  70. return -1;
  71. }
  72. public bool GetValueBool(string valname)
  73. {
  74. foreach (string v in Output)
  75. {
  76. string[] x = v.Split(':');
  77. if (x.GetUpperBound(0) > 0)
  78. {
  79. if (x[0].ToLower() == valname.ToLower())
  80. {
  81. if (x[1].ToLower() == "true")
  82. {
  83. return true;
  84. }
  85. else
  86. {
  87. return false;
  88. }
  89. }
  90. }
  91. }
  92.  
  93. return false;
  94. }
  95. public ObjectSaverLoader(string[] fulltext, string type)//loading
  96. {
  97. Output = fulltext.ToList<string>();
  98. FileName = GetValue("unid");
  99. if (MainClass.IDBlacklist.Contains(FileName))
  100. {
  101. Output = new List<string>();
  102. return;
  103. }
  104.  
  105.  
  106. ObFolder = type;
  107. }
  108.  
  109. public void SaveToFile()
  110. {
  111.  
  112. if (!Directory.Exists("saves/" + SaveName + "/" + ObFolder + "/"))
  113. {
  114. Directory.CreateDirectory("saves/" + SaveName + "/" + ObFolder + "/");
  115.  
  116. }
  117.  
  118. string write = "";
  119. foreach (string v in Output)
  120. {
  121. write = write + v + Environment.NewLine;
  122. }
  123. File.WriteAllText("saves/" + SaveName + "/" + ObFolder + "/" + FileName + ".txt", write);
  124. }
  125.  
  126.  
  127.  
  128. public void SaveString(string fieldname, string content)
  129. {
  130. if (content == null)
  131. {
  132. return;
  133. }
  134. string contentt = content.Replace("\n", "(nll)");
  135. contentt = contentt.Replace("\r", "");
  136. contentt = contentt.Replace("\t", "");
  137. Output.Add(fieldname + ":" + contentt);
  138.  
  139. }
  140. public void SaveString(string fieldname, List<string> content)
  141. {
  142. foreach(string s in content)
  143. {
  144.  
  145. string contentt = s.ToString().Replace("\n", "(nll)");
  146. contentt = contentt.Replace("\r", "");
  147. contentt = contentt.Replace("\t", "");
  148. Output.Add(fieldname + ":" + contentt);
  149. }
  150.  
  151. }
  152. public void SaveString(string fieldname, int content)
  153. {
  154. if (content.ToString() == null)
  155. {
  156. return;
  157. }
  158. string contentt = content.ToString().Replace("\n", "(nll)");
  159. contentt = contentt.Replace("\r", "");
  160. contentt = contentt.Replace("\t", "");
  161. Output.Add(fieldname + ":" + contentt);
  162.  
  163. }
  164.  
  165. public void SaveBool(string fieldname, bool content)
  166. {
  167. Output.Add(fieldname + ":" + content.ToString());
  168.  
  169. }
  170. }
  171.  
  172. public class User
  173. {
  174.  
  175. public User(ObjectSaverLoader source)
  176. {
  177. UnID = source.FileName;
  178. UserName = source.GetValue("username");
  179. password = source.GetValue("password");
  180. DevMode = source.GetValueBool("devmode");
  181. AI = source.GetValueBool("ai");
  182. CurrectActorID = source.GetValue("currentactor");
  183. }
  184.  
  185. public void SaveToFile(string savename)
  186. {
  187. ObjectSaverLoader me = new ObjectSaverLoader("users", savename, UnID);
  188.  
  189.  
  190. me.SaveString("UnID", UnID);
  191. me.SaveString("Username", UserName);
  192. me.SaveString("Password", password);
  193. me.SaveString("Devmode", DevMode.ToString());
  194. me.SaveBool("AI", AI);
  195. if(currentActor != null)
  196. {
  197.  
  198. me.SaveString("CurrentActor", currentActor.UnID);
  199. }
  200.  
  201. me.SaveToFile();
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement