Beispiel #1
0
        /// <summary>
        /// add Link and update file
        /// </summary>
        /// <param name="link"></param>
        public static void AddLink(Link link)
        {
            if (LinkExists(link.Title))
                throw BadInputException.LinkAlreadyExists;

            SyncLink sl = new SyncLink(link);
            Links.Add(sl);
            LinkChanged(0, sl);

            SaveLinksToFile();
        }
Beispiel #2
0
        /// <summary>
        /// create LinkDataForm for creating or editing a link
        /// </summary>
        /// <param name="link">if null a new link will be created</param>
        public LinkDataForm(Link link)
        {
            InitializeComponent();

            if (link != null)
            {
                _oldLink = link;
            }

            comboBox_direction.DataSource = SyncDirection.NameList;

            if(link != null)
            {
                textBox_title.Text = link.Title;
                textBox_folder1.Text = link.Path1;
                textBox_folder2.Text = link.Path2;
                comboBox_direction.SelectedIndex = link.Direction.Id;
                checkBox_remove.Checked = link.Remove;
                checkBox_identifyDrive1ByLabel.Checked = link.Drive1Label != null;
                checkBox_identifyDrive2ByLabel.Checked = link.Drive2Label != null;
                label_driveLabel1.Text = $"(label: {GetDriveLabelFromPath(link.Path1, checkBox_identifyDrive1ByLabel.Checked)})";
                label_driveLabel2.Text = $"(label: {GetDriveLabelFromPath(link.Path2, checkBox_identifyDrive2ByLabel.Checked)})";
            }
        }
Beispiel #3
0
 /// <summary>
 /// Copy link data to Link l
 /// </summary>
 /// <param name="l"></param>
 public void CopyDataTo(Link l)
 {
     l.Title = Title;
     l.Path1 = Path1;
     l.Path2 = Path2;
     l.Remove = Remove;
     l.Direction = Direction;
     l.Drive1Label = Drive1Label;
     l.Drive2Label = Drive2Label;
 }
Beispiel #4
0
        /// <summary>
        /// create link from line
        /// </summary>
        /// <param name="line"></param>
        /// <returns>the created link or null if the format isn't valid</returns>
        public static Link CreateFromLine(string line)
        {
            const int argCount = 7;

            string[] parts = line.Split('\"');

            if (parts.Length != 1 + 2 * argCount)
                return null;

            if (!parts[2].Trim().Equals(":") || parts.Where((x, i) => i > 2 && i < 2 * argCount && i % 2 == 0 && x.Trim() != ",").Count() > 0)
                return null;

            /*!parts[4].Trim().Equals(",") || !parts[6].Trim().Equals(",")
            || !parts[8].Trim().Equals(",") || !parts[10].Trim().Equals(","))*/

            int argIndex = 1;

            string title = parts[argIndex];
            string path1 = parts[argIndex += 2];
            string path2 = parts[argIndex += 2];

            SyncDirection direction;
            bool remove;
            try
            {
                direction = SyncDirection.Parse(parts[argIndex += 2]);
                remove = bool.Parse(parts[argIndex += 2]);
            }
            catch (Exception)
            {
                return null;
            }

            string drive1Label = parts[argIndex += 2];
            string drive2Label = parts[argIndex += 2];

            Link l = new Link(title, path1, path2, direction, remove, drive1Label, drive2Label);
            if (l.Drive1Label != null)
                l.UpdatePath1DriveLetter();
            if (l.Drive2Label != null)
                l.UpdatePath2DriveLetter();
            return l;
        }
Beispiel #5
0
        private void button_save_Click(object sender, EventArgs e)
        {
            #region check input
            bool error = false;
            string title = textBox_title.Text;
            if (title.Length == 0)
            {
                textBox_title.SetBadInputState();
                label_errorTitle.Text = @"the title must not be empty";
                error = true;
            }
            else
            {
                textBox_title.RestoreBorderColor();
                label_errorTitle.Text = "";
            }

            string path1 = textBox_folder1.Text;
            if (path1.Length == 0)
            {
                textBox_folder1.SetBadInputState();
                label_errorFolder1.Text = @"Folder 1 must not be empty";
                error = true;
            }
            else
            {
                textBox_folder1.RestoreBorderColor();
                label_errorFolder1.Text = "";
            }

            string path2 = textBox_folder2.Text;
            if (path2.Length == 0)
            {
                textBox_folder2.SetBadInputState();
                label_errorFolder2.Text = @"Folder 2 must not be empty";
                error = true;
            }
            else
            {
                textBox_folder2.RestoreBorderColor();
                label_errorFolder2.Text = "";
            }

            SyncDirection direction = SyncDirection.FromValue(comboBox_direction.SelectedIndex);
            bool remove = checkBox_remove.Checked;
            bool identifyDrive1ByLabel = checkBox_identifyDrive1ByLabel.Checked;
            bool identifyDrive2ByLabel = checkBox_identifyDrive2ByLabel.Checked;
            #endregion

            string driveLabel1 = null;
            string driveLabel2 = null;
            if (identifyDrive1ByLabel)
            {
                driveLabel1 = GetDriveLabelFromPath(path1, true);
                if (driveLabel1 == null) return;
            }
            if (identifyDrive1ByLabel)
            {
                driveLabel2 = GetDriveLabelFromPath(path1, true);
                if (driveLabel2 == null) return;
            }

            if (error) return;

            try
            {
                Link link = new Link(title, path1, path2, direction, remove, driveLabel1, driveLabel2);

                if (_oldLink != null)
                {
                    //edit link
                    DataManager.ChangeLink(link, _oldLink.Title);
                }
                else
                {
                    //create new link
                    DataManager.AddLink(link);
                }
                Close();
            }
            catch(BadInputException me)
            {
                me.ShowMsgBox();
            }
        }
Beispiel #6
0
        /// <summary>
        /// change Link and update file
        /// </summary>
        /// <param name="link">new link data</param>
        /// <param name="oldTitle">title of old link</param>
        public static void ChangeLink(Link link, string oldTitle)
        {
            if (link.Title != oldTitle && LinkExists(link.Title))
                throw BadInputException.LinkAlreadyExists;

            int pos = GetLinkPosByTitle(oldTitle);
            if (Links[pos].IsRunning)
                throw new ApplicationException("Cannot change Link while its sync is running!");

            link.CopyDataTo(Links[pos]);
            LinkChanged(1, Links[pos]);

            SaveLinksToFile();
        }