Esempio n. 1
0
		public void UpdateFolderContent()
		{
			var existedPaths = new List<string>();
			if (Directory.Exists(OriginalPath))
			{
				foreach (var folder in Directory.GetDirectories(OriginalPath).Select(folderPath => new DirectoryInfo(folderPath)))
				{
					existedPaths.Add(folder.FullName);
					if (FolderContent.Any(x => x.OriginalPath.ToLower().Equals(folder.FullName.ToLower()))) continue;
					var libraryFile = new LibraryFolderLink(Parent);
					libraryFile.Name = folder.Name;
					libraryFile.RootId = RootId;
					var rootFolder = Parent.Parent.Parent.GetRootFolder(RootId);
					libraryFile.RelativePath = (rootFolder.IsDrive ? @"\" : string.Empty) + folder.FullName.Replace(rootFolder.Folder.FullName, string.Empty);
					libraryFile.Type = FileTypes.Folder;
					libraryFile.UpdateFolderContent();
					libraryFile.InitBannerProperties();
					FolderContent.Add(libraryFile);
				}
				foreach (var file in Directory.GetFiles(OriginalPath).Where(x => !x.ToLower().Contains("thumbs.db")).Select(filePath => new FileInfo(filePath)))
				{
					existedPaths.Add(file.FullName);
					if (FolderContent.Any(x => x.OriginalPath.ToLower().Equals(file.FullName.ToLower()))) continue;
					var libraryFile = new LibraryLink(Parent);
					libraryFile.Name = file.Name;
					libraryFile.RootId = RootId;
					var rootFolder = Parent.Parent.Parent.GetRootFolder(RootId);
					libraryFile.RelativePath = (rootFolder.IsDrive ? @"\" : string.Empty) + file.FullName.Replace(rootFolder.Folder.FullName, string.Empty);
					libraryFile.SetProperties();
					libraryFile.InitBannerProperties();
					FolderContent.Add(libraryFile);
				}
			}
			FolderContent.RemoveAll(x => !existedPaths.Any(y => y.ToLower().Equals(x.OriginalPath.ToLower())));
			for (int i = 0; i < FolderContent.Count; i++)
				FolderContent[i].Order = i;
		}
		public void Deserialize(XmlNode node)
		{
			var converter = new FontConverter();

			foreach (XmlNode childNode in node.ChildNodes)
			{
				int tempInt = 0;
				DateTime tempDateTime;
				switch (childNode.Name)
				{
					case "Name":
						_name = childNode.InnerText;
						break;
					case "Identifier":
						Guid tempGuid;
						if (Guid.TryParse(childNode.InnerText, out tempGuid))
							Identifier = tempGuid;
						break;
					case "RowOrder":
						if (int.TryParse(childNode.InnerText, out tempInt))
							_rowOrder = tempInt;
						break;
					case "ColumnOrder":
						if (int.TryParse(childNode.InnerText, out tempInt))
							_columnOrder = tempInt;
						break;
					case "BorderColor":
						if (int.TryParse(childNode.InnerText, out tempInt))
							_borderColor = Color.FromArgb(tempInt);
						break;
					case "BackgroundWindowColor":
						if (int.TryParse(childNode.InnerText, out tempInt))
							_backgroundWindowColor = Color.FromArgb(tempInt);
						break;
					case "ForeWindowColor":
						if (int.TryParse(childNode.InnerText, out tempInt))
							_foreWindowColor = Color.FromArgb(tempInt);
						break;
					case "BackgroundHeaderColor":
						if (int.TryParse(childNode.InnerText, out tempInt))
							_backgroundHeaderColor = Color.FromArgb(tempInt);
						break;
					case "ForeHeaderColor":
						if (int.TryParse(childNode.InnerText, out tempInt))
							_foreHeaderColor = Color.FromArgb(tempInt);
						break;
					case "WindowFont":
						try
						{
							_windowFont = converter.ConvertFromString(childNode.InnerText) as Font;
						}
						catch { }
						break;
					case "HeaderFont":
						try
						{
							_headerFont = converter.ConvertFromString(childNode.InnerText) as Font;
						}
						catch { }
						break;
					case "HeaderAligment":
						if (int.TryParse(childNode.InnerText, out tempInt))
							_headerAlignment = (Alignment)tempInt;
						break;
					case "EnableWidget":
						bool tempBool;
						if (bool.TryParse(childNode.InnerText, out tempBool))
							_enableWidget = tempBool;
						break;
					case "Widget":
						if (!string.IsNullOrEmpty(childNode.InnerText))
							_widget = new Bitmap(new MemoryStream(Convert.FromBase64String(childNode.InnerText)));
						break;
					case "BannerProperties":
						BannerProperties.Deserialize(childNode);
						break;
					case "AddDate":
						if (DateTime.TryParse(childNode.InnerText, out tempDateTime))
							AddDate = tempDateTime;
						break;
					case "LastChanged":
						if (DateTime.TryParse(childNode.InnerText, out tempDateTime))
							_lastChanged = tempDateTime;
						break;
					case "Files":
						Files.Clear();
						foreach (XmlNode fileNode in childNode.ChildNodes)
						{
							LibraryLink libraryFile = null;
							var typeNode = fileNode.SelectSingleNode("Type");
							if (typeNode != null && int.TryParse(typeNode.InnerText, out tempInt))
							{
								var type = (FileTypes)tempInt;
								if (type == FileTypes.Folder)
									libraryFile = new LibraryFolderLink(this);
							}
							if (libraryFile == null)
								libraryFile = new LibraryLink(this);
							libraryFile.Deserialize(fileNode);
							Files.Add(libraryFile);
						}

						#region Order Bug Fix
						if (Files.Count > 0)
						{
							int maxOrder = Files.Select(x => x.Order).Max();
							if (maxOrder == 0)
								for (int i = 0; i < Files.Count; i++)
									if (Files[i].Order != i)
										Files[i].Order = i;
						}
						#endregion

						Files.Sort((x, y) => x.Order.CompareTo(y.Order));
						break;
				}
			}
			if (!BannerProperties.Configured)
			{
				BannerProperties.Text = _name;
				BannerProperties.Font = _headerFont;
				BannerProperties.ForeColor = _foreHeaderColor;
			}
		}
Esempio n. 3
0
		public override void Deserialize(XmlNode node)
		{
			base.Deserialize(node);
			var contentNode = node.SelectSingleNode("FolderContent");
			if (contentNode != null)
				foreach (XmlNode fileNode in contentNode.ChildNodes)
				{
					LibraryLink libraryFile = null;
					var typeNode = fileNode.SelectSingleNode("Type");
					int temp;
					if (typeNode != null && int.TryParse(typeNode.InnerText, out temp))
					{
						var type = (FileTypes)temp;
						if (type == FileTypes.Folder)
							libraryFile = new LibraryFolderLink(Parent);
					}
					if (libraryFile == null)
						libraryFile = new LibraryLink(Parent);
					libraryFile.Deserialize(fileNode);
					FolderContent.Add(libraryFile);
				}
			UpdateFolderContent();
		}