IconInfo.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. using GeekDesk.Constant;
  2. using GeekDesk.Util;
  3. using System;
  4. using System.ComponentModel;
  5. using System.Windows.Media.Imaging;
  6. /// <summary>
  7. /// 图标信息
  8. /// </summary>
  9. namespace GeekDesk.ViewModel
  10. {
  11. [Serializable]
  12. public class IconInfo : INotifyPropertyChanged
  13. {
  14. private string path; //路径
  15. private string name; //文件名
  16. private int count = 0; //打开次数
  17. [field: NonSerialized]
  18. private BitmapImage bitmapImage; //位图
  19. private byte[] imageByteArr; //图片 byte数组
  20. private string content; //显示信息
  21. private bool adminStartUp = false; //始终管理员方式启动 默认否
  22. private byte[] defaultImage; //默认图标
  23. private string startArg; //启动参数
  24. private string lnkPath;
  25. private string relativePath; //相对路径
  26. private IconType iconType = IconType.OTHER;
  27. private bool isChecked = false; //是否选中
  28. public bool IsChecked_NoWrite
  29. {
  30. get
  31. {
  32. return isChecked;
  33. }
  34. set
  35. {
  36. isChecked = value;
  37. OnPropertyChanged("IsChecked_NoWrite");
  38. }
  39. }
  40. public string RelativePath_NoWrite
  41. {
  42. get
  43. {
  44. return relativePath;
  45. }
  46. set
  47. {
  48. relativePath = value;
  49. }
  50. }
  51. public string RelativePath
  52. {
  53. get
  54. {
  55. return relativePath;
  56. }
  57. set
  58. {
  59. relativePath = value;
  60. OnPropertyChanged("RelativePath");
  61. }
  62. }
  63. public string LnkPath_NoWrite
  64. {
  65. get
  66. {
  67. return lnkPath;
  68. }
  69. set
  70. {
  71. lnkPath = value;
  72. }
  73. }
  74. public string LnkPath
  75. {
  76. get
  77. {
  78. return lnkPath;
  79. }
  80. set
  81. {
  82. lnkPath = value;
  83. OnPropertyChanged("LnkPath");
  84. }
  85. }
  86. public string StartArg
  87. {
  88. get
  89. {
  90. return startArg;
  91. }
  92. set
  93. {
  94. startArg = value;
  95. OnPropertyChanged("StartArg");
  96. }
  97. }
  98. public string StartArg_NoWrite
  99. {
  100. get
  101. {
  102. return startArg;
  103. }
  104. set
  105. {
  106. startArg = value;
  107. }
  108. }
  109. public IconType IconType
  110. {
  111. get
  112. {
  113. if (iconType == 0) return IconType.OTHER;
  114. return iconType;
  115. }
  116. set
  117. {
  118. iconType = value;
  119. OnPropertyChanged("IconType");
  120. }
  121. }
  122. public byte[] DefaultImage
  123. {
  124. get
  125. {
  126. return defaultImage;
  127. }
  128. set
  129. {
  130. defaultImage = value;
  131. OnPropertyChanged("DefaultImage");
  132. }
  133. }
  134. public byte[] DefaultImage_NoWrite
  135. {
  136. get
  137. {
  138. return defaultImage;
  139. }
  140. set
  141. {
  142. defaultImage = value;
  143. }
  144. }
  145. public bool AdminStartUp
  146. {
  147. get
  148. {
  149. return adminStartUp;
  150. }
  151. set
  152. {
  153. adminStartUp = value;
  154. OnPropertyChanged("AdminStartUp");
  155. }
  156. }
  157. public int Count
  158. {
  159. get
  160. {
  161. return count;
  162. }
  163. set
  164. {
  165. count = value;
  166. if (StringUtil.IsEmpty(Path))
  167. {
  168. Content = Name + "\n使用次数: " + Count;
  169. }
  170. else
  171. {
  172. Content = Path + "\n" + Name + "\n使用次数: " + Count;
  173. }
  174. OnPropertyChanged("Count");
  175. }
  176. }
  177. public string Name
  178. {
  179. get
  180. {
  181. return name;
  182. }
  183. set
  184. {
  185. name = value;
  186. if (StringUtil.IsEmpty(Path))
  187. {
  188. Content = Name + "\n使用次数: " + Count;
  189. }
  190. else
  191. {
  192. Content = Path + "\n" + Name + "\n使用次数: " + Count;
  193. }
  194. OnPropertyChanged("Name");
  195. }
  196. }
  197. public string Name_NoWrite
  198. {
  199. get
  200. {
  201. return name;
  202. }
  203. set
  204. {
  205. name = value;
  206. if (StringUtil.IsEmpty(Path))
  207. {
  208. content = Name + "\n使用次数: " + Count;
  209. }
  210. else
  211. {
  212. content = Path + "\n" + Name + "\n使用次数: " + Count;
  213. }
  214. }
  215. }
  216. public string Path
  217. {
  218. get
  219. {
  220. return path;
  221. }
  222. set
  223. {
  224. path = value;
  225. if (StringUtil.IsEmpty(Path))
  226. {
  227. Content = Name + "\n使用次数: " + Count;
  228. }
  229. else
  230. {
  231. Content = Path + "\n" + Name + "\n使用次数: " + Count;
  232. }
  233. OnPropertyChanged("Path");
  234. }
  235. }
  236. public string Path_NoWrite
  237. {
  238. get
  239. {
  240. return path;
  241. }
  242. set
  243. {
  244. path = value;
  245. if (StringUtil.IsEmpty(Path))
  246. {
  247. content = Name + "\n使用次数: " + Count;
  248. }
  249. else
  250. {
  251. content = Path + "\n" + Name + "\n使用次数: " + Count;
  252. }
  253. }
  254. }
  255. public BitmapImage BitmapImage
  256. {
  257. get
  258. {
  259. return ImageUtil.ByteArrToImage(ImageByteArr);
  260. }
  261. set
  262. {
  263. bitmapImage = value;
  264. ImageByteArr = ImageUtil.BitmapImageToByte(bitmapImage);
  265. OnPropertyChanged("BitmapImage");
  266. }
  267. }
  268. public BitmapImage BitmapImage_NoWrite
  269. {
  270. get
  271. {
  272. return ImageUtil.ByteArrToImage(ImageByteArr_NoWrite);
  273. }
  274. set
  275. {
  276. bitmapImage = value;
  277. ImageByteArr_NoWrite = ImageUtil.BitmapImageToByte(bitmapImage);
  278. OnPropertyChanged("BitmapImage_NoWrite");
  279. }
  280. }
  281. public byte[] ImageByteArr
  282. {
  283. get
  284. {
  285. return imageByteArr;
  286. }
  287. set
  288. {
  289. imageByteArr = value;
  290. OnPropertyChanged("ImageByteArr");
  291. }
  292. }
  293. public byte[] ImageByteArr_NoWrite
  294. {
  295. get
  296. {
  297. return imageByteArr;
  298. }
  299. set
  300. {
  301. imageByteArr = value;
  302. }
  303. }
  304. public string Content
  305. {
  306. get
  307. {
  308. return content;
  309. }
  310. set
  311. {
  312. content = value;
  313. OnPropertyChanged("Content");
  314. }
  315. }
  316. public string Content_NoWrite
  317. {
  318. get
  319. {
  320. return content;
  321. }
  322. set
  323. {
  324. content = value;
  325. }
  326. }
  327. [field: NonSerializedAttribute()]
  328. public event PropertyChangedEventHandler PropertyChanged;
  329. private void OnPropertyChanged(string propertyName)
  330. {
  331. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  332. if (propertyName!=null && !propertyName.Contains("NoWrite"))
  333. {
  334. CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
  335. }
  336. }
  337. }
  338. }