electron-asar-hot-updater icon indicating copy to clipboard operation
electron-asar-hot-updater copied to clipboard

请问下exe主要做了哪些功能

Open kl-nevermore opened this issue 6 years ago • 13 comments

请问下exe主要做了哪些功能

kl-nevermore avatar Jan 17 '19 09:01 kl-nevermore

@NeverMore-KL

请问下exe主要做了哪些功能

Electron应用关闭后启动EXE程序,EXE会在5秒后替换asar文件

yansenlei avatar Jan 18 '19 00:01 yansenlei

@NeverMore-KL

请问下exe主要做了哪些功能

Electron应用关闭后启动EXE程序,EXE会在5秒后替换asar文件

exe程序能开源么?!

xiaoping6688 avatar Feb 19 '19 11:02 xiaoping6688

@xiaoping6688

可以,我一会提交。

yansenlei avatar Mar 07 '19 03:03 yansenlei

@xiaoping6688 等待中...我写了一个c的版本 打包后 15kb

hanlike avatar Mar 07 '19 04:03 hanlike

我是直接用的:https://github.com/whitesmith/electron-asar-updater/pull/2/commits/7c56ea596a9d15bcee534349c567e60fae6ae108

yansenlei avatar Mar 07 '19 04:03 yansenlei

已经提交 Source&README

yansenlei avatar Mar 07 '19 06:03 yansenlei

@NeverMore-KL

请问下exe主要做了哪些功能

Electron应用关闭后启动EXE程序,EXE会在5秒后替换asar文件

替换后能自动启动就好了!

xiaoping6688 avatar Mar 14 '19 15:03 xiaoping6688

@xiaoping6688 可以啊 你再加一段代码

            string asarSource = "";
            string asarTarget = "";

            System.Threading.Thread.Sleep(5000);

            if(args.Length == 3)
            {   
                try {
                    asarSource = args[0];
                    asarTarget = args[1];

                    System.IO.FileInfo fileInfoSrc = new System.IO.FileInfo(asarSource);
                    System.IO.FileInfo fileInfoDest = new System.IO.FileInfo(asarTarget);

                    if (!fileInfoSrc.Exists) Environment.Exit(1);

                    if (fileInfoDest.Exists)
                    {
                        System.IO.File.Copy(asarSource, asarTarget, true);
                        System.IO.File.Delete(asarSource);
                    }
                    else
                    {
                        System.IO.File.Move(asarSource, asarTarget);
                    }

                    
                    using (Process exeProcess = new Process())
                    {
                        exeProcess.StartInfo.FileName = args[2];
                        exeProcess.Start();
                    }

                }
                catch(Exception e){
                    Console.WriteLine(e.Message);
                }


            }
            else
            {
                Environment.Exit(1);
            }

hanlike avatar Mar 14 '19 15:03 hanlike

已经支持替换后重启 https://github.com/yansenlei/electron-asar-hot-updater/commit/bf74d138fcc113fba92b33c2bf61c6110813da6b

yansenlei avatar Apr 11 '19 15:04 yansenlei

我自己也写了一个类似的,但是最后卡在不能替换。 大佬是弄多一个exe文件来执行替换的。这个思路不错,我也要写个简单的执行脚本来执行改名操作了,但是为什么要在5秒后才执行呢?

sammui4 avatar Aug 16 '19 02:08 sammui4

@sammui4 为了保证程序完全关闭了,没有占用资源的情况下修改文件

yansenlei avatar Aug 16 '19 02:08 yansenlei

嗯 win下 文件是被进程占用的

用一个可视化ui 体验会好一些(比如WPF) 之前的命令行 被PO吐槽像在跑木马植入。

hanlike avatar Aug 16 '19 02:08 hanlike

嘿嘿,拿了这个模块用在我的app,我把updater.cs翻译成了c++版本的,效果一样,好处是不依赖.net。 `//updater.cpp //编译命令:cl -nologo -EHsc -GR -Zc:forScope -Zc:wchar_t -Feupdater /MANIFESTUAC:NO updater.cpp #define _WIN32_WINNT 0x0500 #include <windows.h> #include <Winuser.h> #include <stdio.h> #include <stdlib.h> #include #include #pragma comment(linker, ""/manifestdependency:type='win32'
name='Microsoft.Windows.Common-Controls' version='6.0.0.0'
processorArchitecture='' publicKeyToken='6595b64144ccf1df' language=''"")

#pragma comment(lib, "wsock32.lib") #pragma comment(lib, "Kernel32.LIB") #pragma comment(lib, "user32.lib") #pragma comment(lib, "gdi32.lib")

using namespace std; #define FLUSH_NUM 8192

int main(int argc, char **argv) { std::string updateAsar = ""; std::string appAsar = ""; std::cout << "updater running!\n"; HWND hWnd = GetConsoleWindow(); // wait for the Electron app to close (5 secs) Sleep(5000); //ShowWindow(hWnd, SW_HIDE); if (argc >= 3) {

updateAsar.append(argv[1]);
appAsar.append(argv[2]);

cout << "copy " << updateAsar.c_str() << " to " << appAsar.c_str() << endl;
ifstream in(updateAsar, ios::binary);
ofstream out(appAsar, ios::binary);
if (!in)
{
  printf("open file error");
  return -1;
}
char flush[FLUSH_NUM];
while (!in.eof())
{
  in.read(flush, FLUSH_NUM);
  out.write(flush, in.gcount());
}
printf("copy done\n");
in.close();
out.close();

printf("unlink %s\n", argv[1]);
remove(updateAsar.c_str());

STARTUPINFO si = {sizeof(si)};
DWORD dwExitCode;
PROCESS_INFORMATION procInfo = {0};

if (argc == 4)
{
  printf("run new app %s\n", argv[3]);

  if (!CreateProcess(NULL,
                     argv[3],
                     NULL,
                     NULL,
                     FALSE,
                     0,
                     NULL,
                     NULL, &si, &procInfo))
  {
    printf("CreateProcess failed (%d)./n", GetLastError());
    return 1;
  }
  else
  {
    CloseHandle(procInfo.hThread);
    WaitForSingleObject(procInfo.hProcess, INFINITE);
    GetExitCodeProcess(procInfo.hProcess, &dwExitCode);
    CloseHandle(procInfo.hProcess);
  }
}

} else { return 1; } printf("Quit after 5 sec\n"); Sleep(5000);

return 0; }`

guangmingwan avatar Jun 19 '21 16:06 guangmingwan