Skip to content

Commit

Permalink
初步的独立发布模式支持
Browse files Browse the repository at this point in the history
  • Loading branch information
iccfish committed Dec 29, 2020
1 parent fec8b76 commit 919bd11
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 135 deletions.
186 changes: 93 additions & 93 deletions SimpleUpdater/FSLib.App.SimpleUpdater/Defination/PackageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,161 +3,161 @@ namespace FSLib.App.SimpleUpdater.Defination
using System;
using System.Xml.Serialization;

using global::SimpleUpdater.Attributes;

/// <summary> 表示单个文件信息 </summary>
using global::SimpleUpdater.Attributes;

/// <summary> 表示单个文件信息 </summary>
/// <remarks></remarks>
[Serializable]
[DoNotObfuscate, DoNotObfuscateControlFlow, DoNotObfuscateType, DoNotPrune, DoNotPruneType]
[DoNotCaptureFields, DoNotCaptureVariables, DoNotEncodeStrings] //防止SmartAssembly处理
[DoNotCaptureFields, DoNotCaptureVariables, DoNotEncodeStrings] //防止SmartAssembly处理
public class PackageInfo
{
#region 包信息-需要保存的持久化信息

/// <summary> 文件路径 </summary>
{
#region 包信息-需要保存的持久化信息

/// <summary> 文件路径 </summary>
/// <value></value>
/// <remarks></remarks>
public string FilePath { get; set; }

/// <summary> 文件大小 </summary>
public string FilePath { get; set; }

/// <summary> 文件大小 </summary>
/// <value></value>
/// <remarks></remarks>
public long FileSize { get; set; }

/// <summary> 版本 </summary>
public long FileSize { get; set; }

/// <summary> 版本 </summary>
/// <value></value>
/// <remarks></remarks>
public string Version { get; set; }

public string Version { get; set; }

/// <summary> Hash </summary>
/// <value></value>
/// <remarks></remarks>
public string PackageHash { get; set; }

/// <summary> 包名 </summary>
public string PackageHash { get; set; }

/// <summary> 包名 </summary>
/// <value></value>
/// <remarks></remarks>
public string PackageName { get; set; }

/// <summary> 压缩包文件大小 </summary>
public string PackageName { get; set; }

/// <summary> 压缩包文件大小 </summary>
/// <value></value>
/// <remarks></remarks>
public long PackageSize { get; set; }

/// <summary> 更新模式 </summary>
public long PackageSize { get; set; }

/// <summary> 更新模式 </summary>
/// <value></value>
/// <remarks></remarks>
public UpdateMethod Method { get; set; }

/// <summary> 获得或设置当前文件验证等级 </summary>
public UpdateMethod Method { get; set; }

/// <summary> 获得或设置当前文件验证等级 </summary>
/// <value></value>
/// <remarks></remarks>
public FileVerificationLevel VerificationLevel { get; set; }

/// <summary> 获得或设置本地文件的哈希值 </summary>
public FileVerificationLevel VerificationLevel { get; set; }

/// <summary> 获得或设置本地文件的哈希值 </summary>
/// <value></value>
/// <remarks></remarks>
public string FileHash { get; set; }

public string FileHash { get; set; }

/// <summary>
/// 获得或设置关联的文件
/// 获得或设置关联的文件
/// </summary>
public string[] Files { get; set; }

public string[] Files { get; set; }

/// <summary>
/// 功能标记。
/// 功能标记。
/// </summary>
public string ComponentId { get; set; }


public string ComponentId { get; set; }


#endregion

#region 包本身的公开方法

/// <summary> 解压包 </summary>

#region 包本身的公开方法

/// <summary> 解压包 </summary>
public void Extract()
{
}

/// <summary> 增加失败计数 </summary>
}

/// <summary> 增加失败计数 </summary>
public void IncreaseFailureCounter()
{
RetryCount = (RetryCount ?? 0) + 1;
}

}

#endregion

#region 扩展属性-为了运行时而引入,非固化在升级包中的属性

/// <summary> 获得或设置处理用的上下文环境 </summary>

#region 扩展属性-为了运行时而引入,非固化在升级包中的属性

/// <summary> 获得或设置处理用的上下文环境 </summary>
/// <value></value>
/// <remarks></remarks>
[System.Xml.Serialization.XmlIgnore]
public UpdateContext Context { get; set; }


/// <summary> 获得当前包是否正在下载 </summary>
public UpdateContext Context { get; set; }


/// <summary> 获得当前包是否正在下载 </summary>
/// <value></value>
/// <remarks></remarks>
[XmlIgnore]
public bool IsDownloading { get; internal set; }

/// <summary> 获得当前包是否已经下载 </summary>
public bool IsDownloading { get; internal set; }

/// <summary> 获得当前包是否已经下载 </summary>
/// <value></value>
/// <remarks></remarks>
[XmlIgnore]
public bool IsDownloaded { get; internal set; }

/// <summary> 获得处理过程中最后发生的错误 </summary>
public bool IsDownloaded { get; internal set; }

/// <summary> 获得处理过程中最后发生的错误 </summary>
/// <value></value>
/// <remarks></remarks>
[XmlIgnore]
public Exception LastError { get; internal set; }

/// <summary> 获得重试次数计数 </summary>
public Exception LastError { get; internal set; }

/// <summary> 获得重试次数计数 </summary>
/// <value></value>
/// <remarks></remarks>
[XmlIgnore]
public int? RetryCount { get; internal set; }

/// <summary> 获得本地保存路径 </summary>
public int? RetryCount { get; internal set; }

/// <summary> 获得本地保存路径 </summary>
/// <value></value>
/// <remarks></remarks>
[System.Xml.Serialization.XmlIgnore]
public string LocalSavePath
{
get
{
if (Context == null) throw new InvalidOperationException("尚未附加到上下文中");
if (Context == null) throw new InvalidOperationException("尚未附加到上下文中");
return System.IO.Path.Combine(Context.UpdatePackagePath, PackageName);
}
}

string _sourceUri;

/// <summary> 获得下载的源URL </summary>
string _sourceUri;

/// <summary> 获得下载的源URL </summary>
/// <value></value>
/// <remarks></remarks>
[XmlIgnore]
public string SourceUri
{
get
{
if (Context == null) throw new InvalidOperationException("尚未附加到上下文中");
if (Context == null) throw new InvalidOperationException("尚未附加到上下文中");

return _sourceUri ?? (_sourceUri = Context.GetUpdatePackageFullUrl(PackageName));
}
}

/// <summary>
/// 获得或本地的Hash值
}

/// <summary>
/// 获得或本地的Hash值
/// </summary>
[XmlIgnore]
public string LocalHash { get; private set; }

bool? _hashResult;

/// <summary> 获得本地的包文件是否有效 </summary>
bool? _hashResult;

/// <summary> 获得本地的包文件是否有效 </summary>
/// <value></value>
/// <remarks></remarks>
[XmlIgnore]
Expand All @@ -170,28 +170,28 @@ public bool? IsLocalFileValid
LocalHash = Wrapper.ExtensionMethod.GetFileHash(path, PackageHash.Length == 32);
return _hashResult ?? (_hashResult = LocalHash == PackageHash);
}
}

/// <summary> 获得已下载的长度 </summary>
}

/// <summary> 获得已下载的长度 </summary>
/// <value></value>
/// <remarks></remarks>
[XmlIgnore]
public long DownloadedSize { get; internal set; }

public long DownloadedSize { get; internal set; }

#endregion

#region 辅助方法


#region 辅助方法

/// <summary>
/// 确定是否有此标记位
/// 确定是否有此标记位
/// </summary>
/// <param name="level"></param>
/// <returns></returns>
internal bool HasVerifyFlag(FileVerificationLevel level)
{
return (level & VerificationLevel) > 0;
}

}

#endregion
}
}
}
26 changes: 22 additions & 4 deletions SimpleUpdater/FSLib.App.SimpleUpdater/Defination/UpdateContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace FSLib.App.SimpleUpdater.Defination
public class UpdateContext
{
private static ILogger _logger = LogManager.Instance.GetLogger<UpdateContext>();

/// <summary>
/// 获得或设置相关联的主窗口。所有的提示界面将会以其为父窗口
/// </summary>
Expand All @@ -40,14 +40,27 @@ public UpdateContext()
//如果当前启动路径位于TEMP目录下,则处于临时路径模式
var temppath = System.IO.Path.GetTempPath();
var assemblyPath = Assembly.GetExecutingAssembly().Location;

_logger.LogInformation($"Current user temporary path was set to {temppath}");
_logger.LogInformation($"Current assembly was located at '{assemblyPath}'");
#if NET5_0
if (string.IsNullOrEmpty(assemblyPath))
{
assemblyPath = AppContext.BaseDirectory;
NeedStandaloneUpdateClientSupport = true;
_logger.LogInformation($"Current app context was located at '{assemblyPath}'");
_logger.LogInformation($"Unable get location from assembly, probably program released as a single file. A standalone updater client will be required to perform upgrade.");
}
#endif

if (assemblyPath.IndexOf(temppath, StringComparison.OrdinalIgnoreCase) != -1)
{
UpdateTempRoot = System.IO.Path.GetDirectoryName(assemblyPath);
UpdateTempRoot = File.Exists(assemblyPath) ? Path.GetDirectoryName(assemblyPath) : assemblyPath;
IsInUpdateMode = true;
}
else
{
UpdateTempRoot = System.IO.Path.Combine(temppath, Guid.NewGuid().ToString());
UpdateTempRoot = System.IO.Path.Combine(temppath, Guid.NewGuid().ToString("N").Substring(0, 8));
IsInUpdateMode = false;

//尝试自动加载升级属性
Expand Down Expand Up @@ -553,7 +566,7 @@ public string LogFile
}
}
}

/// <summary>
/// 获得或设置是否不经提示便自动更新
/// </summary>
Expand Down Expand Up @@ -648,5 +661,10 @@ public DialogStyle DialogStyle
get => UpdateInfo?.DialogStyle ?? _dialogStyle ?? DialogStyle.Default;
set => _dialogStyle = value;
}

/// <summary>
/// 获得或设置是否需要独立的更新客户端支持
/// </summary>
public bool NeedStandaloneUpdateClientSupport { get; private set; }
}
}
Loading

0 comments on commit 919bd11

Please sign in to comment.