Пример #1
0
        private void CopyFiles()
        {
            string remoteDir = Path.GetDirectoryName(Globals.RemoteProjectFile);

            IOSupport.CopyFile(Globals.RemoteProjectFile, Globals.ProjectFile, true);
            IOSupport.CopyFile(remoteDir + @"\Settings\categories.xml", Globals.SettingsDir + "categories.xml", true);
        }
Пример #2
0
        void histItemCtrl_DeleteHistImageSelected(object sender, EventArgs e)
        {
            ImageSelectorHistItemCtrl ctrl = (ImageSelectorHistItemCtrl)sender;

            if (pnlImageHistory.Controls.Contains(ctrl))
            {
                pnlImageHistory.Controls.Remove(ctrl);
            }

            IOSupport.DeleteFile(ctrl.ImagePath);
        }
Пример #3
0
        /// <summary>
        /// Create default options for chromedriver session (i.e. can be augmented by extraParameters if any)
        /// </summary>
        /// <param name="browserDataPath"></param>
        /// <param name="extraParameters"></param>
        /// <returns></returns>
        private static ChromeOptions CreateOptions(string browserDataPath, string[] extraParameters)
        {
            ChromeOptions options = new ChromeOptions();

            if (IOSupport.IsDirectoryWriteable(browserDataPath))
            {
                options.AddArgument($"--user-data-dir={browserDataPath}");
            }
            if (extraParameters != null)
            {
                options.AddArguments(extraParameters);
            }

            return(options);
        }
Пример #4
0
        void histItemCtrl_HistImageSelected(object sender, EventArgs e)
        {
            ImageSelectorHistItemCtrl ctrl = (ImageSelectorHistItemCtrl)sender;

            // rename current to history file
            string curFile = navigationViewerCtrl1.CurrentImagePath;

            IOSupport.RenameFile(curFile, GetHistFilename(curFile));

            // use selected image
            IOSupport.RenameFile(ctrl.ImagePath, curFile);

            ShowCurrentImage();
            ShowPastImages();

            navigationViewerCtrl1.RefreshCurrentImage();
        }
Пример #5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (String.IsNullOrEmpty(Globals.ProjectFile) == false)
                {
                    string destFile = Globals.MapsDir + Path.GetFileName(dlg.FileName);
                    IOSupport.CopyFile(dlg.FileName, destFile);

                    int index = dgrMaps.Rows.Add();
                    dgrMaps[0, index].Value = Path.GetFileName(dlg.FileName);
                    dgrMaps[1, index].Value = "";
                }
            }
        }
Пример #6
0
        private void SetImage(int index, string filepath)
        {
            string fileName    = navigatorPoint.Id + "-" + Path.GetFileName(filepath);
            string curFileName = string.Empty;

            // Set point image and picture box image
            switch (index)
            {
            case 0:
                pbStraight.Image    = ImageLoader.GetImageFromFile(filepath, pbStraight.Width, pbStraight.Height);
                curFileName         = navigatorPoint.Img1;
                navigatorPoint.Img1 = fileName;
                break;

            case 1:
                pbLeft.Image        = ImageLoader.GetImageFromFile(filepath, pbLeft.Width, pbLeft.Height);;
                curFileName         = navigatorPoint.Img2;
                navigatorPoint.Img2 = fileName;
                break;

            case 2:
                pbBehind.Image      = ImageLoader.GetImageFromFile(filepath, pbBehind.Width, pbBehind.Height);;
                curFileName         = navigatorPoint.Img3;
                navigatorPoint.Img3 = fileName;
                break;

            case 3:
                pbRight.Image       = ImageLoader.GetImageFromFile(filepath, pbRight.Width, pbRight.Height);;
                curFileName         = navigatorPoint.Img4;
                navigatorPoint.Img4 = fileName;
                break;
            }


            string destinationDir = Globals.ImagesDir + navigatorPath.Id + "\\";

            IOSupport.CopyFile(filepath, destinationDir + fileName);

            // Rename old file name (filename to _filename)
            if (String.IsNullOrEmpty(curFileName) == false && File.Exists(destinationDir + curFileName))
            {
                IOSupport.RenameFile(destinationDir + curFileName, destinationDir + "_" + curFileName);
            }
        }
Пример #7
0
        private void lnkSelectNewImage_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "Image files (.jpg, .jpeg, .bmp, .gif, .png)|*.jpg;*.jpeg;*.bmp;*.gif;*.png";
            dlg.Multiselect = false;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                // rename current image (name#dd-MMM-yyyy seconds.extension)
                string curFile = navigationViewerCtrl1.CurrentImagePath;
                IOSupport.RenameFile(curFile, GetHistFilename(curFile));
                // rename selected image to be used for Navigator point
                IOSupport.CopyFile(dlg.FileName, curFile);

                ShowCurrentImage();
                ShowPastImages();

                navigationViewerCtrl1.RefreshCurrentImage();
            }
        }
Пример #8
0
        public static void Start(bool _useConsole, string directoryPath, int _intervalBetweenPurge)
        {
            // Create color pattern
            foreach (var color in Enum.GetValues(typeof(ConsoleColor)))
            {
                colorPattern += $"({color}" + "{)" + "|";
            }
            colorPattern += "(})";

            // Save variable and instantiate logging
            intervalBetweenPurge = _intervalBetweenPurge;
            useConsole           = _useConsole;
            if (IOSupport.IsDirectoryWriteable(directoryPath))
            {
                logEntries = new ConcurrentQueue <LogEntry>();
                Started    = true;
                Write($"Application {Process.GetCurrentProcess().ProcessName} started (logging enabled)");
                task = new CancellableTask((token) =>
                {
                    while (!((CancellationToken)token).IsCancellationRequested)
                    {
                        PurgeQueue(directoryPath);
                        if (applicationExiting)
                        {
                            Write($"Application {Process.GetCurrentProcess().ProcessName} terminated", LogEntry.SeverityType.High);
                            PurgeQueue(directoryPath);
                            return;
                        }
                        task.SleepOrExit(intervalBetweenPurge);
                    }
                });
                task.Start();
            }
            else
            {
                Write($"Application {Process.GetCurrentProcess().ProcessName} started (logging disabled)");
            }
        }
Пример #9
0
        private void btnPointInfoSave_Click(object sender, EventArgs e)
        {
            if (lstPoints.SelectedItem != null && lstPaths.SelectedItem != null)
            {
                NavigatorPath  selectedPath  = (NavigatorPath)lstPaths.SelectedItem;
                NavigatorPoint selectedPoint = (NavigatorPoint)lstPoints.SelectedItem;

                // change all associated image file names
                string[] files = Directory.GetFiles(Globals.ImagesDir + selectedPath.Id, selectedPoint.Id + "*.*");
                foreach (string file in files)
                {
                    string[] pointFileNameParts = Path.GetFileName(file).Split("-".ToCharArray());
                    if (pointFileNameParts.Length != 2)
                    {
                        throw new Exception("File name is not in proper format");
                    }

                    IOSupport.RenameFile(file, Globals.ImagesDir + selectedPath.Id + "\\" + txtPointId.Text + "-" + pointFileNameParts[1]);
                }

                // Update selected point info
                if (String.IsNullOrEmpty(txtNextPointAngle.Text) == false)
                {
                    selectedPoint.NextPointAngle = Int32.Parse(txtNextPointAngle.Text);
                }
                if (String.IsNullOrEmpty(txtPointId.Text) == false)
                {
                    selectedPoint.Id = txtPointId.Text;
                }

                // sav e project file
                if (place != null)
                {
                    LoadSave.Save(Globals.ProjectFile, place);
                }
            }
        }
Пример #10
0
        private void SyncFolder(string srcFolder, string destFolder)
        {
            IOSupport.CreateDirectory(destFolder);
            // 1. FILES
            // copy all files if does not exists or changed
            List <string> existingFiles = new List <string>();

            foreach (string srcFile in Directory.GetFiles(srcFolder))
            {
                string name     = Path.GetFileName(srcFile);
                string destFile = destFolder + "\\" + name;
                if (File.Exists(destFile))
                {
                    // copy only if modified
                    FileInfo srcFileInfo  = new FileInfo(srcFile);
                    FileInfo destFileInfo = new FileInfo(destFile);
                    if (srcFileInfo.LastWriteTime != destFileInfo.LastWriteTime)
                    {
                        IOSupport.CopyFile(srcFile, destFile, true);
                    }
                }
                else
                {
                    // new file
                    IOSupport.CopyFile(srcFile, destFile, true);
                }

                existingFiles.Add(name);
            }
            // Delete unused files
            foreach (string destFile in Directory.GetFiles(destFolder))
            {
                string name = Path.GetFileName(destFile);
                if (existingFiles.Contains(name) == false)
                {
                    IOSupport.DeleteFile(destFile);
                }
            }

            // 2. FOLDERS
            List <string> existingFolders = new List <string>();

            // recursively process all sub directories
            foreach (string subfolder in Directory.GetDirectories(srcFolder))
            {
                string foldername = new DirectoryInfo(subfolder).Name;
                // recursive call
                SyncFolder(subfolder, destFolder + "\\" + foldername);

                existingFolders.Add(foldername);
            }
            // delete all unused folders
            foreach (string destDir in Directory.GetDirectories(destFolder))
            {
                string name = new DirectoryInfo(destDir).Name;
                if (existingFolders.Contains(name) == false)
                {
                    IOSupport.DeleteDirectory(destDir, true);
                }
            }
        }