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);

相关文章:

  • 2021-10-15
  • 2021-10-24
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
  • 2021-12-09
  • 2022-02-12
相关资源
相似解决方案