Пример #1
0
        private void AddEntries(ICollection <string> filePaths)
        {
            bool alwaysReplace = false;

            foreach (var filePath in filePaths)
            {
                try
                {
                    var entryName = Path.GetFileName(filePath);
                    entryName = EPFArchive.ValidateEntryName(entryName);

                    var entry = Entries.FirstOrDefault(item => item.Name == entryName);

                    if (entry == null)
                    {
                        var epfEntry = _epfArchive.CreateEntry(entryName, filePath);
                    }
                    else
                    {
                        bool replace = false;

                        if (alwaysReplace)
                        {
                            replace = true;
                        }
                        else
                        {
                            //TODO: Create better WinForms dialog for this purpose
                            var replaceAnswer = DialogProvider.ShowReplaceFileQuestion($"Entry '{entryName}' already exists. Do you want to replace it?", "Entry already exists.");

                            if (replaceAnswer == DialogAnswer.Yes)
                            {
                                replace = true;
                            }
                            else if (replaceAnswer == DialogAnswer.No)
                            {
                                replace = false;
                            }
                            else if (replaceAnswer == DialogAnswer.Cancel)
                            {
                                break;
                            }
                            //else if(replaceAnswer == DialogAnswe.All)
                            //{
                            //    replace = true;
                            //    alwaysReplace = true;
                            //}
                        }

                        if (replace)
                        {
                            _epfArchive.ReplaceEntry(entryName, filePath);
                        }
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Status.Log.Warning($"Unable to add new entry '{filePath}'. {ex.Message}");
                }
            }
        }