public static List <FileInfoX> GetLocalFileList() { List <FileInfoX> files = new List <FileInfoX>(); foreach (var item in GetFiles(Settings.WatchDir)) { if (!System.IO.File.Exists(item)) { continue; } else if (System.Text.RegularExpressions.Regex.IsMatch(item, @"\.enc\.\d{12}$")) { continue; } var info = new System.IO.FileInfo(item); FileInfoX x = new FileInfoX(); DateTime lastWriteUtc = new DateTime(info.LastWriteTime.Year, info.LastWriteTime.Month, info.LastWriteTime.Day, info.LastWriteTime.Hour, info.LastWriteTime.Minute, info.LastWriteTime.Second).ToUniversalTime(); //do it this way to avoid milisecond comparison problemsinfo.LastWriteTime; //!FileNameProcessing x.CloudFileName = item.Replace(Settings.WatchDir, "").Replace(System.IO.Path.DirectorySeparatorChar, '~') + ".enc"; x.LastModifiedUtc = lastWriteUtc; x.LocalFileName = item.Replace(Settings.WatchDir, ""); x.CloudFileNameWithEmbeddedData = x.CloudFileName + "." + OwnCloudClient.GetUnixUtcTimeStamp(lastWriteUtc); x.EncryptedCloudFileNameWithEmbeddedData = EncryptFileName(x.CloudFileNameWithEmbeddedData); files.Add(x); } return(files); }
public static List <FileInfoX> GetRemoteFileList() { List <FileInfoX> files = new List <FileInfoX>(); string json = string.Empty; using (WebClient wc = new WebClient()) { wc.Headers.Add("Pragma: no-cache"); wc.Headers.Add(string.Format("Cookie: PHPSESSID={0}", phpId)); json = wc.DownloadString(string.Concat(Settings.OwnCloudUrl, "files/api.php?action=getfiles&dir=")); } JObject o = JObject.Parse(json); JToken jtk = o.Root; foreach (var x in jtk.Values()) { if (x != null && x.SelectToken("name") != null) { string cloudNamePlusDate = DecryptFileName(x.SelectToken("name").ToString().Trim(new char[] { '\"' })); FileInfoX fix = CreateFileInfoXFromcloudFileNameWithEmbeddedData(cloudNamePlusDate); if (x != null) { files.Add(fix); } } } return(files); }
public static bool ShouldDownload(FileInfoX f) { string fname = Settings.WatchDir + f.LocalFileName; bool shouldDownload = false; if (System.IO.File.Exists(fname)) { System.IO.FileInfo info = new FileInfo(fname); shouldDownload = info.LastWriteTime.ToUniversalTime() < f.LastModifiedUtc; } else { shouldDownload = true; } return(shouldDownload); }
public static bool ShouldDownload(FileInfoX f) { string fname = Settings.WatchDir + f.LocalFileName; bool shouldDownload = false; if (System.IO.File.Exists(fname)) { System.IO.FileInfo info = new FileInfo(fname); shouldDownload = info.LastWriteTime.ToUniversalTime() < f.LastModifiedUtc; } else { shouldDownload = true; } return shouldDownload; }
public static List<FileInfoX> GetLocalFileList() { List<FileInfoX> files = new List<FileInfoX>(); foreach (var item in GetFiles(Settings.WatchDir)) { if (!System.IO.File.Exists(item)) continue; else if (System.Text.RegularExpressions.Regex.IsMatch(item, @"\.enc\.\d{12}$")) continue; var info = new System.IO.FileInfo(item); FileInfoX x = new FileInfoX(); DateTime lastWriteUtc = new DateTime(info.LastWriteTime.Year, info.LastWriteTime.Month, info.LastWriteTime.Day, info.LastWriteTime.Hour, info.LastWriteTime.Minute, info.LastWriteTime.Second).ToUniversalTime(); //do it this way to avoid milisecond comparison problemsinfo.LastWriteTime; //!FileNameProcessing x.CloudFileName = item.Replace(Settings.WatchDir, "").Replace(System.IO.Path.DirectorySeparatorChar, '~') + ".enc"; x.LastModifiedUtc = lastWriteUtc; x.LocalFileName = item.Replace(Settings.WatchDir, ""); x.CloudFileNameWithEmbeddedData = x.CloudFileName + "." + OwnCloudClient.GetUnixUtcTimeStamp(lastWriteUtc); x.EncryptedCloudFileNameWithEmbeddedData = EncryptFileName(x.CloudFileNameWithEmbeddedData); files.Add(x); } return files; }