Example #1
0
        private bool ExtractionFile(ZipArchiveEntry entry, FileInfo info, FileOverride fileOverride, ExtractionOptions extractionOptions)
        {
            var isExist = info.Exists;

            if (fileOverride == FileOverride.Never && isExist)
            {
                Watch?.Info($"文件已存在 [{info.FullName}]。");
                return(true);
            }
            if (fileOverride == FileOverride.Newer && isExist && entry.LastModifiedTime <= info.LastWriteTime)
            {
                Watch?.Info($"文件已存在 [{info.FullName}]。");
                return(true);
            }

            bool retry;

            do
            {
                retry = false;
                try
                {
                    entry.WriteToFile(info.FullName, extractionOptions);
                    if (!isExist)
                    {
                        newFiles.Add(info.FullName);
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    if (fileOverride == FileOverride.Try)
                    {
                        Watch?.Info($"覆盖文件失败,自动忽略并继续。失败原因:{e.Message}");
                        return(true);
                    }
                    var dr = Helper.AbortRetryIgnore(this.Owner, $"覆盖文件失败,是否重试?失败原因:{Environment.NewLine}{e.Message}");
                    if (dr == DialogResult.Abort)
                    {
                        Watch?.Error($"覆盖文件失败,失败原因:{e.Message}");
                        Watch?.Faild();
                        return(false);
                    }
                    if (dr == DialogResult.Retry)
                    {
                        Watch?.Info($"覆盖文件失败,正在重试。失败原因:{e.Message}");
                        retry = true;
                    }
                    else if (dr == DialogResult.Ignore)
                    {
                        Watch?.Info($"覆盖文件失败,忽略该操作。失败原因:{e.Message}");
                        return(true);
                    }
                }
            } while (retry);

            return(true);
        }