Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private bool TryExecuteFile(ScriptFile file)
        {
            bool retry;

            do
            {
                var flag = ExecuteFile(file.File, out string message);
                if (flag)
                {
                    file.Status = ScriptStatus.Success;
                    return(true);
                }

                retry = false;
                var dr = Helper.AbortRetryIgnore(this.Owner, $"执行脚本失败,是否重试?失败原因:{Environment.NewLine}{message}");
                if (dr == DialogResult.Abort)
                {
                    Watch?.Error($"执行脚本失败,失败原因:{message}");
                    Watch?.Faild();
                    file.Status = ScriptStatus.Failed;
                    return(false);
                }

                if (dr == DialogResult.Retry)
                {
                    Watch?.Info("重试该脚本。");
                    retry = true;
                }
                else if (dr == DialogResult.Ignore)
                {
                    Watch?.Info("忽略该脚本。");
                    file.Status = ScriptStatus.Ignore;
                    return(true);
                }
            } while (retry);

            return(true);
        }