/// <summary> /// Compare the given file md5 Hash /// </summary> /// <param name="filePathLocal">Local FilePath (Will read and generate the md5 hash directly from file)</param> /// <param name="filePathRemote">Remote Filepath</param> /// <returns>Returns false if the file version is different</returns> public static bool CompareVersions(string filePathLocal, string filePathRemote) { if (File.Exists(filePathLocal) && File.Exists(filePathRemote)) { string localFileVersion = FileVersionHandler.GetVersion(filePathLocal); string localFilePath = Path.Combine(Path.GetDirectoryName(filePathLocal), localFileVersion); string onlineFilePath = Path.Combine(Path.GetDirectoryName(filePathRemote), localFileVersion); if (!File.Exists(onlineFilePath)) { return(false); } } return(true); }
/// <summary> /// Recursive method to create the directory of all the files in the root /// </summary> /// <param name="path">Path of the folder to</param> /// <param name="onlyAdd">True if is going to only add the files to the writer parameter</param> /// <param name="writer">Writer to use in case only add is true</param> /// <param name="level">Depth of the current directory</param> private static void Create(string path, bool onlyAdd, XmlWriter writer, int level) { if (Directory.Exists(path)) { string directoryFileName = GetFilePath(path); try { // Create an XmlWriterSettings object with the correct options. XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = ("\t"); settings.OmitXmlDeclaration = true; if (File.Exists(directoryFileName)) { File.Delete(directoryFileName); } string[] files = Directory.GetFiles(path); if (!onlyAdd) { writer = XmlWriter.Create(directoryFileName, settings); writer.WriteStartElement(RootNode); } foreach (string file in files) { FileInfo fileInfo = new FileInfo(file); if (fileInfo.Extension != String.Empty) { writer.WriteStartElement(FileNode); writer.WriteAttributeString(LastWriteAttribute, File.GetLastWriteTime(file).ToString()); writer.WriteAttributeString(FileSizeAttribute, fileInfo.Length.ToString()); writer.WriteString(file); writer.WriteEndElement(); } } string[] directories = Directory.GetDirectories(path); level++; foreach (string directory in directories) { Create(directory, true, writer, level); if (level < depth) { Create(directory, false, null, level); } } if (!onlyAdd) { writer.WriteEndElement(); writer.Flush(); } } finally { if (!onlyAdd) { if (writer != null) { writer.Close(); FileVersionHandler.CreateVersion(directoryFileName); } } } } }