示例#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
        void DoOperation()
        {
            int ctor = 0;

            foreach (var e in elems)
            {
                if (e.Destinations.Count == 0)
                {
                    ctor++;
                }
                else
                {
                    if (OnCalcuateTime != null)
                    {
                        OnCalcuateTime(ctor);
                    }
                    ctor++;
                    if (e.Destinations.Count == 1)
                    {
                        //Single copy
                        var dest = e.Destinations[0].Destination;
                        if (dest == Define.RemoveIDString)
                        {
                            continue;
                        }
                        if (File.Exists(dest))
                        {
                            //Application passing
                            var process = System.Diagnostics.Process.Start(dest, e.ImageSourcePath);
                            if (Core.Config.BehaviorConfig.WaitExternalApp)
                            {
                                process.WaitForExit();
                            }
                            else if (Core.Config.BehaviorConfig.WaitExternalAppIdling)
                            {
                                process.WaitForInputIdle();
                            }

                            if (e.DistributionMode == Bright.Data.GroupingElement.DistributionModes.Move)
                            {
                                OnHandledException.Invoke(new ArgumentException("アプリケーションへ渡すように設定されていますが、振り分け方法が「移動」になっています。Typictは、この振り分け方法を無視します。ファイルは削除されません。"));
                            }
                            if (OnUpdateOperatedList != null)
                            {
                                OnUpdateOperatedList.Invoke(new OperatedData()
                                {
                                    Dest            = dest,
                                    Orig            = e.ImageSourcePath,
                                    DistributedMode = Bright.Data.GroupingElement.DistributionModes.App,
                                    Succeed         = true
                                });
                            }
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(e.NewName))
                            {
                                dest = Path.Combine(dest, e.NewName);
                            }
                            else
                            {
                                dest = Path.Combine(dest, Path.GetFileName(e.ImageSourcePath));
                            }
                            bool ret = DoMoveCopy(e.ImageSourcePath, ref dest, e.DistributionMode);
                            if (OnUpdateOperatedList != null)
                            {
                                OnUpdateOperatedList.Invoke(new OperatedData()
                                {
                                    Dest            = dest,
                                    Orig            = e.ImageSourcePath,
                                    DistributedMode = e.DistributionMode,
                                    Succeed         = ret
                                });
                            }
                        }
                    }
                    else
                    {
                        //Multi copy
                        bool   deletable         = true;
                        int    count             = 0;
                        string firstDistributeTo = null;
                        foreach (var deste in e.Destinations)
                        {
                            count++;
                            var dest = deste.Destination;
                            if (dest == Define.RemoveIDString)
                            {
                                continue;
                            }
                            if (File.Exists(dest))
                            {
                                //Application passing
                                var process = System.Diagnostics.Process.Start(dest, e.ImageSourcePath);
                                if (Core.Config.BehaviorConfig.WaitExternalApp)
                                {
                                    process.WaitForExit();
                                }
                                else if (Core.Config.BehaviorConfig.WaitExternalAppIdling)
                                {
                                    process.WaitForInputIdle();
                                }
                                deletable = false;
                                if (e.DistributionMode == Bright.Data.GroupingElement.DistributionModes.Move)
                                {
                                    OnHandledException.Invoke(new ArgumentException("アプリケーションへ渡すように設定されていますが、振り分け方法が「移動」になっています。Typictは、この振り分け方法を無視します。ファイルは削除されません。"));
                                }
                                if (OnUpdateOperatedList != null)
                                {
                                    OnUpdateOperatedList.Invoke(new OperatedData()
                                    {
                                        Dest            = dest,
                                        Orig            = e.ImageSourcePath,
                                        DistributedMode = Bright.Data.GroupingElement.DistributionModes.App,
                                        Succeed         = true
                                    });
                                }
                            }
                            else
                            {
                                bool ret = false;
                                if (!String.IsNullOrEmpty(e.NewName))
                                {
                                    dest = Path.Combine(dest, e.NewName);
                                }
                                else
                                {
                                    dest = Path.Combine(dest, Path.GetFileName(e.ImageSourcePath));
                                }
                                if (!Core.Config.BehaviorConfig.MultiCopyTreatsReference || String.IsNullOrEmpty(firstDistributeTo) || !File.Exists(firstDistributeTo))
                                {
                                    if (e.DistributionMode == Bright.Data.GroupingElement.DistributionModes.Link)
                                    {
                                        ret = DoMoveCopy(e.ImageSourcePath, ref dest, Bright.Data.GroupingElement.DistributionModes.Link);
                                    }
                                    else
                                    {
                                        ret = DoMoveCopy(e.ImageSourcePath, ref dest, Bright.Data.GroupingElement.DistributionModes.Copy);
                                    }
                                    if (ret)
                                    {
                                        firstDistributeTo = dest;
                                    }
                                    System.Diagnostics.Debug.WriteLine("First distribute to:" + firstDistributeTo);
                                    if (OnUpdateOperatedList != null)
                                    {
                                        OnUpdateOperatedList.Invoke(new OperatedData()
                                        {
                                            Dest            = dest,
                                            Orig            = e.ImageSourcePath,
                                            DistributedMode = e.DistributionMode == Bright.Data.GroupingElement.DistributionModes.Link ? Bright.Data.GroupingElement.DistributionModes.Link : Bright.Data.GroupingElement.DistributionModes.Copy,
                                            Succeed         = ret
                                        });
                                    }
                                }
                                else
                                {
                                    System.Diagnostics.Debug.WriteLine("Alternate link from:" + firstDistributeTo + " to " + dest);
                                    ret = DoMoveCopy(firstDistributeTo, ref dest, Bright.Data.GroupingElement.DistributionModes.Link);
                                    if (OnUpdateOperatedList != null)
                                    {
                                        OnUpdateOperatedList.Invoke(new OperatedData()
                                        {
                                            Dest            = dest,
                                            Orig            = firstDistributeTo,
                                            DistributedMode = Bright.Data.GroupingElement.DistributionModes.Link,
                                            Succeed         = ret
                                        });
                                    }
                                }
                                if (!ret)
                                {
                                    deletable = false;
                                }
                            }
                        }
                        if (e.DistributionMode == Bright.Data.GroupingElement.DistributionModes.Move)
                        {
                            if (deletable)
                            {
                                File.Delete(e.ImageSourcePath);
                            }
                            else
                            {
                                OnHandledException.Invoke(new InvalidOperationException("マルチコピーで1件以上の移動エラーが発生しているため、ファイルの削除は行われません。"));
                            }
                        }
                    }
                }
                if (Finished)
                {
                    break;
                }
            }
        }