Example #1
0
        internal void AddVirtualFile(string realPathFile, string treeFolderPath)
        {
            string folderPath = treeFolderPath.ToLowerInvariant();
            string fileName   = Path.GetFileName(realPathFile);

            bool folderExist = treeFiles.ContainsKey(folderPath);

            if (folderExist && treeFiles[folderPath].FileExist(fileName))
            {
                DialogResult result = (OverwriteAll) ? DialogResult.Retry
                                                     : new CustomMessageBox(String.Format((ExplorerForm.LocaleRU)
                                                                             ? "Файл: {0}{1} уже существует!\nПерезаписать файл?"
                                                                             : "File: {0}{1} already exist!\nOverwrite file?",
                                                                                          folderPath, fileName)).ShowDialog();
                switch (result)
                {
                case DialogResult.Retry:     // all
                case DialogResult.Yes:
                    OverwriteAll = (result == DialogResult.Retry);
                    var list = new List <string>();
                    list.Add(folderPath + fileName.ToLowerInvariant());
                    DeleteFile(list, false);
                    break;

                default:
                    return;     // не добавляем дубликаты
                }
            }

            System.IO.FileInfo file = new System.IO.FileInfo(realPathFile);

            DATLib.FileInfo fileDat = new DATLib.FileInfo();
            fileDat.name            = file.Name;
            fileDat.info.Size       = (int)file.Length;
            fileDat.info.PackedSize = -1;
            fileDat.pathTree        = treeFolderPath;

            dat.AddFile(realPathFile, fileDat);

            if (!folderExist)
            {
                treeFiles.Add(folderPath, new TreeFiles(treeFolderPath));
            }

            treeFiles[folderPath].AddFile(new KeyValuePair <string, DATLib.FileInfo>(folderPath + fileDat.name.ToLowerInvariant(), fileDat));

            TotalFiles++;

            if (shouldSave != SaveType.New)
            {
                shouldSave = SaveType.Append;
            }
        }