public static bool SaveVideoInfo(VideoInfo videoInfo) { // MyLog.Add("SaveVideoInfo"); listVideoInfos[videoInfo.index] = videoInfo; UpdateVideo updateVideo = new UpdateVideo(); updateVideo.UpdateMVE(videoInfo); updateVideo.UpdateXBMC(videoInfo); updateVideo.UpdateMB(videoInfo); // delete prior statsfile, if any, so stats will be re-calced string statsFile = MyFile.EnsureDataFile("stats", Config.settings.exportExt, "stats"); if (statsFile != null) { MyFile.DeleteFile(statsFile); } return(true); }
protected void BackgroundWorkerScanSource_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // delete prior statsfile, if any, so stats will be re-calced string statsFile = MyFile.EnsureDataFile("stats", Config.settings.exportExt, "stats"); if (statsFile != null) { MyFile.DeleteFile(statsFile); } VideoInfos_RunWorkerCompleted("scan", "Scanning done", sender, e); }
public static bool RotateLogs(string file) { if (File.Exists(file)) { // rotate log, if bigger than X KB int rotateLogSize = 250 * 1024; FileInfo logFileInfo = MyFile.FileInfo(file); if (logFileInfo.Length >= rotateLogSize) { RotateFiles(file); MyFile.DeleteFile(file); return(true); } } return(false); }
public bool DeleteFilter(string preset) { bool ret = false; if (MessageBox.Show("Delete Filter Preset [" + preset + "]", "Filter Preset", MessageBoxButtons.YesNo) == DialogResult.Yes) { string dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", preset); // MessageBox.Show(dataFile); if (MyFile.DeleteFile(dataFile)) { // MessageBox.Show("Deleted Filter Preset [" + preset + "]"); comboBoxFilters.Items.Remove(comboBoxFilters.SelectedItem); LoadFilters(); // subFormFilterForm.ResetForm(); ret = true; } else { MessageBox.Show("Error deleting Filter Preset [" + preset + "]"); } } return(ret); }
public bool SyncUpVideoSource(FileInfo sourceFileInfo) { // clean up old uploads IEnumerable <string> files = MyFile.EnumerateFiles(@"sync", "*.gz"); foreach (string file in files) { MyFile.DeleteFile(file); } // compress file, video source string compressedFile = @"sync\" + MyFile.SafeFileName(sourceFileInfo.Name); if (!MyFile.Compress(sourceFileInfo.FullName, compressedFile)) { return(false); } // rename file so has 'rand' key/iv Random random = new Random(); int rand = random.Next(0, MyEncrypt.sharedKeys.Length - 1); string uploadFile = compressedFile.Replace("." + Config.settings.exportExt, "-" + rand + "." + Config.settings.exportExt); File.Move(compressedFile + ".gz", uploadFile + ".gz"); string key = MyEncrypt.sharedKeys[rand]; string iv = MyEncrypt.GenerateIV(); string delimiter = "#"; // now encrypt compressed file contents string fileContents = MyFile.ReadAllBinaryToString(uploadFile + ".gz"); string contentsHeader = "{"; contentsHeader += "\"apiKey\":\"" + this.apiKey + "\", "; contentsHeader += "\"iv\":\"" + iv + "\", "; contentsHeader += "\"sync\":" + MySerialize.ToJSON(Sync.syncSettings); contentsHeader += "}"; contentsHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes(contentsHeader)); fileContents = MyEncrypt.EncryptRJ256(key, iv, fileContents); if (fileContents == null) { return(false); } contentsHeader = MyEncrypt.EncryptRJ256(key, iv, contentsHeader); string contentsToEncode = contentsHeader + delimiter + fileContents; // write base64 encoded file File.WriteAllText(uploadFile + ".enc", contentsToEncode); // log it FileInfo encodedFileInfo = MyFile.FileInfo(uploadFile + ".enc"); if (encodedFileInfo == null) { return(false); } MyLog.Add(String.Format("Encrypted {0} to {1}", encodedFileInfo.Name, MyFile.FormatSize(encodedFileInfo.Length))); // test decrypt fileContents = MyFile.ReadAllText(uploadFile + ".enc"); string[] fileParts = fileContents.Split(new string[] { delimiter }, StringSplitOptions.None); fileContents = MyEncrypt.DecryptRJ256(key, iv, fileParts[1]); MyFile.DeleteFile(uploadFile + ".gz"); MyFile.WriteAllBinaryFromString(uploadFile + ".gz", fileContents); // post encoded file to website string url = apiURL; List <KeyValuePair <string, string> > headers = new List <KeyValuePair <string, string> > { }; headers.Add(new KeyValuePair <string, string>("api-key", apiKey)); headers.Add(new KeyValuePair <string, string>("access-token", iv)); Upload(url, uploadFile + ".enc", headers); return(true); }