示例#1
0
        private bool DoMoveCopy(string source, ref string dest, Bright.Data.GroupingElement.DistributionModes distMode)
        {
            if (source == dest)
            {
                return(false);
            }
            if (File.Exists(dest))
            {
                DialogResult dr = AllTrap;
                if (dr == DialogResult.None)
                {
                    using (var dp = new Duplication(source, dest))
                    {
                        dr = dp.ShowDialog();
                        if (dp.AllTrap)
                        {
                            AllTrap = dr;
                        }
                    }
                }
                switch (dr)
                {
                case DialogResult.Cancel:
                    return(false);

                case DialogResult.Abort:
                    Finished = true;
                    return(false);

                case DialogResult.OK:
                    FileSystem.DeleteFile(dest, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
                    break;

                case DialogResult.Retry:
                    string destn = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest));
                    string ext   = Path.GetExtension(dest);
                    int    ctor  = 1;
                    while (File.Exists(destn + "(" + ctor + ")" + ext))
                    {
                        ctor++;
                    }
                    dest = destn + "(" + ctor + ")" + ext;
                    break;

                default:
                    throw new Exception("Duplicate processing error.");
                }
            }
            try
            {
                if (distMode == Bright.Data.GroupingElement.DistributionModes.Copy)
                {
                    File.Copy(source, dest);
                }
                else if (distMode == Bright.Data.GroupingElement.DistributionModes.Move)
                {
                    File.Move(source, dest);
                }
                else if (distMode == Bright.Data.GroupingElement.DistributionModes.Link)
                {
                    using (var shortcut = new ShellLink())
                    {
                        shortcut.Description = "Image file link, created by typict";
                        shortcut.TargetPath  = source;
                        shortcut.ShowCommand = SW.NORMAL;

                        shortcut.Save(dest + ".lnk");
                    }
                }
                else
                {
                    throw new ArgumentException("distribution mode is invalid: value " + ((int)distMode).ToString());
                }
            }
            catch (Exception e)
            {
                if (OnHandledException != null)
                {
                    OnHandledException.Invoke(e);
                }
                return(false);
            }
            return(true);
        }
示例#2
0
        private bool DoMoveCopy(string source, ref string dest, Bright.Data.GroupingElement.DistributionModes distMode)
        {
            if (source == dest)
                return false;
            if (File.Exists(dest))
            {
                DialogResult dr = AllTrap;
                if (dr == DialogResult.None)
                {
                    using (var dp = new Duplication(source, dest))
                    {
                        dr = dp.ShowDialog();
                        if (dp.AllTrap)
                            AllTrap = dr;
                    }
                }
                switch (dr)
                {
                    case DialogResult.Cancel:
                        return false;
                    case DialogResult.Abort:
                        Finished = true;
                        return false;
                    case DialogResult.OK:
                        FileSystem.DeleteFile(dest, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
                        break;
                    case DialogResult.Retry:
                        string destn = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest));
                        string ext = Path.GetExtension(dest);
                        int ctor = 1;
                        while (File.Exists(destn + "(" + ctor + ")" + ext))
                            ctor++;
                        dest = destn + "(" + ctor + ")" + ext;
                        break;
                    default:
                        throw new Exception("Duplicate processing error.");
                }
            }
            try
            {
                if (distMode == Bright.Data.GroupingElement.DistributionModes.Copy)
                {
                    File.Copy(source, dest);
                }
                else if (distMode == Bright.Data.GroupingElement.DistributionModes.Move)
                {
                    File.Move(source, dest);
                }
                else if (distMode == Bright.Data.GroupingElement.DistributionModes.Link)
                {
                    using (var shortcut = new ShellLink())
                    {
                        shortcut.Description = "Image file link, created by typict";
                        shortcut.TargetPath = source;
                        shortcut.ShowCommand = SW.NORMAL;

                        shortcut.Save(dest + ".lnk");
                    }
                }
                else
                {
                    throw new ArgumentException("distribution mode is invalid: value " + ((int)distMode).ToString());
                }
            }
            catch (Exception e)
            {
                if (OnHandledException != null)
                    OnHandledException.Invoke(e);
                return false;
            }
            return true;
        }