public void Upload(string url, string fileName, List <KeyValuePair <string, string> > headers)
        {
            WebClient webClient = new WebClient();

            // add event handlers for completed and progress changed
            webClient.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressChanged);
            webClient.UploadFileCompleted   += new UploadFileCompletedEventHandler(UploadFileCompleted);

            webClient.Headers.Add("user-agent", Config.settings.about.product + " " + Config.settings.about.version);
            foreach (KeyValuePair <string, string> header in headers)
            {
                webClient.Headers.Add(header.Key, header.Value);
            }
            Uri uri = new Uri(url);

            string sync = MySerialize.ToJSON(Sync.syncSettings);


            MyLog.Add("Upload to uri:" + uri.ToString() + " sync:" + sync + " file:" + fileName);


            int progress = 0;

            subFormProgressSyncUp.Value(progress);
            subFormProgressSyncUp.Text("Uploading..");

            webClient.UploadFileAsync(uri, fileName);
        }
Exemple #2
0
        public static bool Save(Form formMain)
        {
            // save main window size/position
            settings.window.left   = formMain.Left;
            settings.window.top    = formMain.Top;
            settings.window.height = formMain.Height;
            settings.window.width  = formMain.Width;

            // save maximized state
            settings.window.maximized = formMain.WindowState == FormWindowState.Maximized ? true : false;

            // set modified, version
            settings.about = GetConfigSettingsAbout();

            string configFile = MyFile.EnsureDataFile("settings", settings.exportExt, "config");

            if (configFile == null)
            {
                return(false);
            }

            MyLog.RotateFiles(configFile);

            // save new settings
            MySerialize.ToFile(settings.exportFormat, configFile, settings);

            return(true);
        }
Exemple #3
0
        public static bool Save()
        {
            if (listVideoInfos == null)
            {
                return(false);
            }

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            MyLog.Add("Saving VideoItems -->");

            foreach (ConfigSettings.Source settingsSource in Config.settings.sources)
            {
                string dataFile = MyFile.EnsureDataFile("videos", Config.settings.exportExt, "data", settingsSource.alias);
                if (dataFile == null)
                {
                    continue;
                }

                List <VideoInfo> saveVideoInfos = new List <VideoInfo>(listVideoInfos.Count());
                saveVideoInfos = listVideoInfos.Where(x => x.sourceAlias == settingsSource.alias && x.videoItem != null && x.videoItem.title != null).OrderBy(x => x.videoItem.title).ToList();


                if (saveVideoInfos == null)
                {
                    continue;
                }
                int nbrVideoInfos = saveVideoInfos.Count();
                if (nbrVideoInfos == 0)
                {
                    continue;
                }

                MyLog.RotateFiles(dataFile);
                MySerialize.ToFile(Config.settings.exportFormat, dataFile, saveVideoInfos);


                FileInfo fileInfo = MyFile.FileInfo(dataFile);
                string   toFile   = "to " + dataFile.Replace(MyFile.exeDirectory, "");
                if (fileInfo != null)
                {
                    toFile += " " + MyFile.FormatSize(fileInfo.Length);
                }
                MyLog.Add("Saved " + nbrVideoInfos + " VideoItems " + toFile);
            }

            stopWatch.Stop();
            MyLog.AddElapsed("<-- in ", stopWatch.Elapsed);

            return(true);
        }
        public static bool Save()
        {
            string dataFile = MyFile.EnsureDataFile("stats", Config.settings.exportExt, "stats");

            if (dataFile == null)
            {
                return(false);
            }

            MyLog.RotateFiles(dataFile);

            MySerialize.ToFile(Config.settings.exportFormat, dataFile, videoInfoStats);

            return(true);
        }
        public static bool Save()
        {
            string syncFile = MyFile.EnsureDataFile("sync", Config.settings.exportExt, "sync");

            if (syncFile == null)
            {
                return(false);
            }

            MyLog.RotateFiles(syncFile);

            // save new settings
            MySerialize.ToFile(Config.settings.exportFormat, syncFile, syncSettings);

            return(true);
        }
        /// <summary>
        /// parse the MVE .mve file
        /// </summary>
        /// <param name="mveFile"></param>
        /// <returns></returns>
        public bool UpdateMVE(VideoInfo videoInfo)
        {
            if (!Config.settings.createMVE)
            {
                return(false);
            }

            string videoInfoFile = videoInfo.videoDirectory + @"\movie.mve";
            bool   ret           = MySerialize.ToFile(Config.settings.exportFormat, videoInfoFile, videoInfo);
            string message       = "mve video item to " + videoInfoFile;

            if (ret)
            {
                MyLog.Add("wrote " + videoInfoFile);
            }
            else
            {
                MyLog.Add("error writing to " + videoInfoFile);
            }
            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);
        }
Exemple #8
0
        public bool SaveFilter(string filterName)
        {
            if (filterName.Length == 0)
            {
                return(false);
            }
            string dataFile;

            if (filterName == "<_reset_>")
            {
                MessageBox.Show("Cannot Save filter");
                subFormFilterForm.ResetForm();
                return(false);
            }
            else if (filterName == "<filter when closed>")
            {
                dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", "filter when closed");
                if (dataFile == null)
                {
                    return(false);
                }
            }
            else if (filterName == "<last saved filter>")
            {
                MessageBox.Show("Cannot Save filter.\nThis Filter will be automaticlly be saved when you Save another Filter.");
                return(false);
            }
            else
            {
                filterName = MyFile.SafeFileName(filterName);
                dataFile   = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", filterName);
                if (dataFile == null)
                {
                    return(false);
                }
                allow_comboBoxPreset_SelectedIndexChanged = false;
                comboBoxFilters.Text = filterName;
                allow_comboBoxPreset_SelectedIndexChanged = true;
            }

            FilterInfo filterInfo = subFormFilterForm.GetFilterForm();

            MyLog.RotateFiles(dataFile);

            filterInfo.about = Config.GetConfigSettingsAbout();
            filterInfo.name  = filterName;
            if (filterInfo.description == null)
            {
                filterInfo.description = "";
            }

            MySerialize.ToFile(Config.settings.exportFormat, dataFile, filterInfo);

            MyLog.Add("Saved Filter Preset " + dataFile.Replace(MyFile.exeDirectory, ""));

            // make a copy of last saved filter
            if (filterName != "<last saved filter>" && filterName != "<filter when closed>")
            {
                dataFile = MyFile.EnsureDataFile("Filter", Config.settings.exportExt, "filters", "last saved filter");
                if (dataFile == null)
                {
                    return(false);
                }
                MyLog.RotateFiles(dataFile);


                MySerialize.ToFile(Config.settings.exportFormat, dataFile, filterInfo);
                MyLog.Add("Saved Filter Preset " + dataFile.Replace(MyFile.exeDirectory, ""));
            }


            return(true);
        }