6-30更新内容:
由于编写代码的时候没有考虑到更新文件存放的真实位置,所以可能导致软件目录下其他文件夹文件不能更新,代码稍作修改:
更新配置文件中用相对路径表示文件更新后的保存位置,如:
<file name="doc\1.rar" src="http://localhost/1.rar" version="3" size="1394007" isrestart="false" />
程序中需要判断是否存在软件目录下的doc目录,并且在临时更新文件夹update中创建临时更新二级目录防止不同目录下有相同文件名的文件
关键位置代码修改如下:
/*相对路径标示文件保存位置*/
string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "update", file.Name);
if (!Directory.Exists(Path.GetDirectoryName(tempPath)))
Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
string truePath=Path.GetDirectoryName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,file.Name));
if (!Directory.Exists(truePath))
Directory.CreateDirectory(truePath);
client.DownloadFileAsync(new Uri(file.DownloadUrl), tempPath);
string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "update", file.Name);
if (!Directory.Exists(Path.GetDirectoryName(tempPath)))
Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
string truePath=Path.GetDirectoryName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,file.Name));
if (!Directory.Exists(truePath))
Directory.CreateDirectory(truePath);
client.DownloadFileAsync(new Uri(file.DownloadUrl), tempPath);