Ejemplo n.º 1
0
        public static ImportResourceResult CopyToDic(ResourceFolder parentDic, IEnumerable <string> files, IProgressMonitor monitor, CancellationToken token, IEnumerable <string> fileTypeSuffix = null)
        {
            ImportResourceResult importResult = new ImportResourceResult();

            importResult.FileTypeSuffix = fileTypeSuffix;
            importResult.Token          = token;
            List <FileOptionHelp.FileData> dealDithFiles = new List <FileOptionHelp.FileData>();

            FileOptionHelp.IsMainThread();
            int pathsFileSystemCount = FileOptionHelp.GetPathsFileSystemCount(files);

            monitor.BeginTask(LanguageInfo.Menu_File_ImportFile, pathsFileSystemCount);
            foreach (FileOptionHelp.FileData fileData in FileOptionHelp.CreateFileDatas(files))
            {
                if (!token.IsCancellationRequested)
                {
                    ResourceItem resourceItem = !File.Exists((string)fileData.FilePath) || fileData.Attributes.HasFlag((Enum)FileAttributes.Hidden) ? FileOptionHelp.CopyDir(parentDic, fileData, ref importResult, dealDithFiles, monitor) : FileOptionHelp.CopyFile(parentDic, fileData, ref importResult, dealDithFiles, monitor);
                    if (resourceItem != null)
                    {
                        importResult.ImportResources.Add(resourceItem);
                        importResult.AddResourcePanelItems.Add(resourceItem);
                    }
                }
                else
                {
                    break;
                }
            }
            return(importResult);
        }
Ejemplo n.º 2
0
        private static ResourceItem CopyFile(ResourceFolder parent, FileOptionHelp.FileData filePath, ref ImportResourceResult importResult, List <FileOptionHelp.FileData> dealDithFiles, IProgressMonitor monitor)
        {
            ResourceItem result;

            try
            {
                if (importResult.Token.IsCancellationRequested)
                {
                    result = null;
                }
                else
                {
                    bool flag = false;
                    if (null != importResult.FileTypeSuffix)
                    {
                        flag = true;
                        if (importResult.FileTypeSuffix.Contains(filePath.FilePath.Extension))
                        {
                            flag = false;
                        }
                    }
                    flag |= filePath.FilePath.Extension.Equals(".ccs", StringComparison.OrdinalIgnoreCase);
                    if (flag)
                    {
                        monitor.Step(1);
                        result = null;
                    }
                    else if (dealDithFiles.Contains(filePath))
                    {
                        result = null;
                    }
                    else
                    {
                        List <string> list = FileOptionHelp.ProcessPairResources(filePath.FilePath);
                        if (list != null)
                        {
                            filePath.CanRename = false;
                        }
                        FilePath filePath2 = parent.BaseDirectory.Combine(new string[]
                        {
                            filePath.Name
                        });
                        DialogResult dialogRes = new DialogResult();
                        if (!FileOptionHelp.VerifyPath(filePath2))
                        {
                            monitor.Step(1);
                            monitor.ReportError(string.Format(LanguageInfo.MessageBox199_PathContainsChinese, filePath.FilePath), null);
                            result = null;
                        }
                        else if (filePath.FilePath.IsChildPathOf(parent.BaseDirectory))
                        {
                            if (!FileOptionHelp.VerifyPath(filePath.FilePath))
                            {
                                monitor.Step(1);
                                monitor.ReportError(string.Format(LanguageInfo.MessageBox199_PathContainsChinese, filePath.FilePath), null);
                                result = null;
                            }
                            else
                            {
                                ResourceItem resourceItem  = null;
                                ResourceItem resourceItem2 = Services.ProjectOperations.AddResourceItem(parent, filePath.FilePath, monitor, out resourceItem);
                                if (resourceItem != null)
                                {
                                    if (resourceItem.Parent != parent)
                                    {
                                        importResult.AddResourcePanelItems.Add(resourceItem.Parent);
                                    }
                                    else
                                    {
                                        importResult.AddResourcePanelItems.Add(resourceItem);
                                    }
                                }
                                File.SetAttributes(filePath.FilePath, FileAttributes.Normal);
                                result = resourceItem2;
                            }
                        }
                        else
                        {
                            if (File.Exists(filePath2))
                            {
                                if (!importResult.DialogResult.IsChangedAll)
                                {
                                    if (FileOptionHelp.IsMainThread())
                                    {
                                        ImportFileDialog importFileDialog = new ImportFileDialog(Services.MainWindow, filePath.CanRename);
                                        importFileDialog.RefreshMessage(filePath.Name);
                                        dialogRes = importFileDialog.ShowRun();
                                    }
                                    else
                                    {
                                        AutoResetEvent autoReset = new AutoResetEvent(false);
                                        GLib.Timeout.Add(0u, delegate
                                        {
                                            ImportFileDialog importFileDialog2 = new ImportFileDialog(Services.MainWindow, filePath.CanRename);
                                            importFileDialog2.RefreshMessage(filePath.Name);
                                            dialogRes = importFileDialog2.ShowRun();
                                            autoReset.Set();
                                            return(false);
                                        });
                                        autoReset.WaitOne();
                                    }
                                    importResult.DialogResult = dialogRes;
                                }
                                switch (importResult.DialogResult.ButtonResult)
                                {
                                case EImportFileButtonResult.KeepBoth:
                                    if (filePath.CanRename)
                                    {
                                        filePath2 = FileOptionHelp.RenameFile(filePath2);
                                    }
                                    else
                                    {
                                        monitor.ReportWarning(string.Format(LanguageInfo.MessageBox200_CannotRename, filePath.FilePath));
                                    }
                                    break;

                                case EImportFileButtonResult.Skip:
                                    result = null;
                                    return(result);
                                }
                            }
                            if (list != null)
                            {
                                string text = FileOptionHelp.CheckFiles(list);
                                if (!string.IsNullOrWhiteSpace(text))
                                {
                                    monitor.Step(1);
                                    string message = string.Format(LanguageInfo.MessageBox195_NoMatchPng, filePath.FilePath, text);
                                    monitor.ReportWarning(message);
                                    result = null;
                                    return(result);
                                }
                                foreach (FilePath current in list)
                                {
                                    FilePath filePath3 = current.ToRelative(filePath.FilePath.ParentDirectory).ToAbsolute(parent.BaseDirectory);
                                    string   path      = filePath3.ParentDirectory;
                                    if (!Directory.Exists(path))
                                    {
                                        Directory.CreateDirectory(path);
                                    }
                                    FileService.CopyFile(current, filePath3);
                                    File.SetAttributes(filePath3, FileAttributes.Normal);
                                    dealDithFiles.Add(new FileOptionHelp.FileData(current));
                                }
                            }
                            FileService.CopyFile(filePath.FilePath, filePath2);
                            File.SetAttributes(filePath2, FileAttributes.Normal);
                            ResourceItem resourceItem3 = Services.ProjectOperations.AddResourceItem(parent, filePath2, monitor);
                            if (resourceItem3 is Project && importResult.DialogResult.ButtonResult == EImportFileButtonResult.Replace)
                            {
                                ((Project)resourceItem3).Reload(monitor);
                            }
                            result = resourceItem3;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                monitor.Step(1);
                monitor.ReportError(string.Format(LanguageInfo.Output_ImportFailed, filePath.FilePath), exception);
                result = null;
            }
            return(result);
        }