Skip to content

Commit

Permalink
V1.0.1.20241120_beta code files
Browse files Browse the repository at this point in the history
  • Loading branch information
Hgnim committed Nov 20, 2024
1 parent e9d5afc commit 6d6a686
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions EasyUpdateFromGithub/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Performance", "SYSLIB1045:转换为“GeneratedRegexAttribute”。", Justification = "<挂起>", Scope = "member", Target = "~M:EasyUpdateFromGithub.UpdateFromGithub.CheckUpdateX(System.String)~System.Boolean")]
[assembly: SuppressMessage("Performance", "SYSLIB1045:转换为“GeneratedRegexAttribute”。", Justification = "<挂起>", Scope = "member", Target = "~P:EasyUpdateFromGithub.UpdateFromGithub.ProgramVersion")]
[assembly: SuppressMessage("Performance", "CA1822:将成员标记为 static", Justification = "<挂起>", Scope = "member", Target = "~M:EasyUpdateFromGithub.UpdateFromGithub.InstallFile(EasyUpdateFromGithub.UpdateFromGithub.InfoOfInstall,System.String,System.Boolean,System.Boolean,System.Int32)")]
24 changes: 17 additions & 7 deletions EasyUpdateFromGithub/UpdateFromGithub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public long ProgramVersionNumber
get => programVersionNumber;
}

string cacheDir = System.IO.Path.GetTempPath() + @"EasyUpdateFromGithub\";
string cacheDir = System.IO.Path.GetTempPath() + @"EasyUpdateFromGithub";
/// <summary>
/// 进行文件处理的临时文件夹<br/>
/// 如果没有设置该项,则默认为"C:\Users\[user]\AppData\Local\Temp\EasyUpdateFromGithub\"
Expand All @@ -70,6 +70,15 @@ public string CacheDir
set => cacheDir = value;
get => cacheDir;
}
/// <summary>
/// 更简单的设置文件处理的临时文件夹<br/>
/// 只需将该值设置为主程序名或其它不带特殊字符的名字即可<br/>
/// 它将会被自动匹配入临时文件夹路径内
/// </summary>
public string EasySetCacheDir
{
set=>cacheDir= $@"{System.IO.Path.GetTempPath()}{value}\EasyUpdateFromGithub";
}

/// <summary>
/// 根据RepositoryURL检查当前程序是否有可用的更新
Expand Down Expand Up @@ -138,13 +147,13 @@ public class InfoOfInstall
{
InfoOfInstall ioi = new()
{
newFileDir = $@"{dlFilePath}_AllFile\"
newFileDir = $@"{dlFilePath}_AllFile"
};
Directory.CreateDirectory(ioi.newFileDir);
if (unPack)
UnPack(dlFilePath, ioi.newFileDir);
else
File.Move(dlFilePath, $"{ ioi.newFileDir}{Path.GetFileName(dlFilePath)}");
File.Move(dlFilePath, $@"{ ioi.newFileDir}\{Path.GetFileName(dlFilePath)}",true);


ioi.installerFile = $@"{cacheDir}\EasyUpdateFromGithub_RunInstall.exe";
Expand All @@ -168,8 +177,9 @@ public class InfoOfInstall
/// 如果为空,则使用当前程序所在的目录
/// <paramref name="useAdmin">是否使用管理员权限运行</paramref>
/// <paramref name="openOnOver">在执行完成后是否自动打开可执行文件</paramref>
/// <paramref name="waitTime">安装进程等待程序退出的时间,单位: ms</paramref>
/// </param>
public static void InstallFile(InfoOfInstall ioi,string? installDir=null,bool useAdmin=false,bool openOnOver=true)
public void InstallFile(InfoOfInstall ioi,string? installDir=null,bool useAdmin=false,bool openOnOver=true,int waitTime=0)
{
if (installDir != null)
ioi.oldFileDir = installDir;
Expand All @@ -183,16 +193,16 @@ public static void InstallFile(InfoOfInstall ioi,string? installDir=null,bool us
UseShellExecute = true,
CreateNoWindow = true,
FileName = ioi.installerFile,
Arguments = $" {ioi.newFileDir} {ioi.oldFileDir}"
Arguments = $" {waitTime} {ioi.newFileDir} {ioi.oldFileDir}"
}
};
if (useAdmin)
process.StartInfo.Verb = "RunAs";
if (openOnOver)
process.StartInfo.Arguments += $" {ioi.exeFile}";
process.StartInfo.Arguments += $" \"{ioi.exeFile} &\"";
else
process.StartInfo.Arguments += " NULL";
process.Start();
process.Start();
}
}
}
19 changes: 11 additions & 8 deletions EasyUpdateFromGithub_RunInstall/MainProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,29 @@ static bool moveFile(string oldPath,string newPath) {
/// </summary>
/// <param name="argc"></param>
/// <param name="argv">
/// 参数是必须的,否则程序可能会无法正常运行<br/>
/// 0: 默认<br/>
/// 1: 被移动的所有文件所在的目录<br/>
/// 2: 目标目录<br/>
/// 3: 执行安装完后的可执行文件路径,为NULL时禁用<br/>
/// 1: 执行前等待的时间
/// 2: 被移动的所有文件所在的目录<br/>
/// 3: 目标目录<br/>
/// 4: 执行安装完后的可执行文件路径,为NULL时禁用<br/>
/// </param>
/// <returns></returns>
int main(int argc, char* argv[])
{
try {
Sleep(stoi(argv[1]));
cout << "开始检查文件..." << endl;
vector<string> moveFiles = getDirAllFile(argv[1]);
vector<string> moveFiles = getDirAllFile(argv[2]);
rego:;
if (moveFiles.size() > 0) {
cout << "开始执行文件操作..." << endl;
for (auto& file : moveFiles) {
moveFile(argv[1] + string("\\") + file, argv[2] + string("\\") + file);
moveFile(argv[2] + string("\\") + file, argv[3] + string("\\") + file);
}
}
cout << "验证文件..." << endl;
moveFiles = getDirAllFile(argv[1]);
moveFiles = getDirAllFile(argv[2]);
if (moveFiles.size() > 0)
{
cout << "验证失败,等待1秒后重新尝试执行..." << endl;
Expand All @@ -73,8 +76,8 @@ int main(int argc, char* argv[])
}
cout << "完成!" << endl;

if (argv[3] != "NULL")
system(argv[3]);
if (string(argv[4]) != "NULL")
system(argv[4]);
system("timeout /t 3");
}
catch (...) {
Expand Down

0 comments on commit 6d6a686

Please sign in to comment.