コード例 #1
0
 public SyncForm(FileSync fs)
 {
     InitializeComponent();
     FileSync     = fs;
     SrcBox.Text  = fs.SrcMacro;
     DestBox.Text = fs.DestPath;
     Text         = "Edit File Sync";
 }
コード例 #2
0
        private void SyncBtn_Click(object sender, EventArgs e)
        {
            if (SyncList.SelectedItem == null)
            {
                LogLine("Nothing selected to sync.");
            }

            FileSync fs = (FileSync)SyncList.SelectedItem;

            CopyFile(fs, out string message);
            LogLine(message);
        }
コード例 #3
0
        private void DrawSyncListBoxItem(object sender, DrawItemEventArgs e)
        {
            ListBox list = (ListBox)sender;

            if (e.Index < 0)
            {
                return;
            }
            FileSync fs = (FileSync)list.Items[e.Index];

            e.DrawBackground();
            e.DrawFocusRectangle();

            Brush brush      = new SolidBrush(e.ForeColor);
            int   textHeight = e.Font.Height;

            StringFormat format = new StringFormat();

            format.LineAlignment = StringAlignment.Center;
            format.FormatFlags   = StringFormatFlags.NoWrap;

            Rectangle rect = new Rectangle();

            rect.Y      = e.Bounds.Top;
            rect.Width  = e.Bounds.Width / 2 - textHeight / 2;
            rect.Height = e.Bounds.Height;

            // Left string
            format.Alignment = StringAlignment.Near;
            rect.X           = e.Bounds.Left;
            string display = EllipsizeFront(fs.SrcMacro, rect.Width, e);

            e.Graphics.DrawString(display, e.Font, brush, rect, format);

            // Right string
            format.Alignment = StringAlignment.Far;
            rect.X           = e.Bounds.Left + e.Bounds.Width / 2 + textHeight / 2;
            display          = EllipsizeFront(fs.DestPath, rect.Width, e);
            e.Graphics.DrawString(display, e.Font, brush, rect, format);

            //arrow
            int cx    = e.Bounds.Left + (e.Bounds.Width / 2);
            int cy    = e.Bounds.Top + (e.Bounds.Height / 2);
            int width = textHeight;

            rect = new Rectangle(cx - width / 2, cy - textHeight / 2, width, textHeight);
            e.Graphics.DrawImage(ArrowPic.Image, rect); //TODO: better way of getting image?
        }
コード例 #4
0
        private void AddBtn_Clicked(object sender, EventArgs e)
        {
            SyncForm syncForm = new SyncForm();

            syncForm.ShowDialog(); // blocking

            FileSync fs = syncForm.FileSync;

            if (string.IsNullOrWhiteSpace(fs.SrcMacro))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(fs.DestPath))
            {
                return;
            }

            SyncList.Items.Add(fs);

            StoreFSFile(); // maybe don't need this here.
        }
コード例 #5
0
        public CopyResult CopyFile(FileSync fs, out string message)
        {
            try
            {
                string srcPath  = fs.SrcPath; // calculates from SrcMacro
                string destPath = fs.DestPath;
                if (string.IsNullOrWhiteSpace(srcPath))
                {
                    throw new Exception("Source file not found.");
                }
                if (!File.Exists(srcPath))
                {
                    throw new Exception($"Source file {srcPath} doesn't exist.");
                }

                if (File.Exists(destPath))
                {
                    if (FilesAreEqual(srcPath, destPath))
                    {
                        message = $"{destPath} already up to date.";
                        return(CopyResult.UpToDate);
                    }
                    else
                    {
                        File.Delete(destPath);
                    }
                }

                File.Copy(srcPath, destPath);
                message = $"{srcPath} was copied to {destPath}";
                return(CopyResult.Success);
            }
            catch (Exception ex)
            {
                message = $"Failed to copy to {fs.DestPath}: " + ex.Message;
                return(CopyResult.Fail);
            }
        }
コード例 #6
0
 public SyncForm()
 {
     InitializeComponent();
     FileSync = new FileSync();
     Text     = "New File Sync";
 }