ide: selfupgrade feature

git-svn-id: svn://ultimatepp.org/upp/trunk@12289 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-09-20 13:50:59 +00:00
parent e37ae68e71
commit 3e56ba07e7
5 changed files with 65 additions and 11 deletions

View file

@ -105,16 +105,22 @@ bool LocalProcess::DoStart(const char *command, const Vector<String> *arg, bool
HANDLE hp = GetCurrentProcess();
CreatePipe(&hInputRead, &hInputWriteTmp, NULL, 0);
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
CreatePipe(&hInputRead, &hInputWriteTmp, &sa, 0);
DuplicateHandle(hp, hInputWriteTmp, hp, &hInputWrite, 0, FALSE, DUPLICATE_SAME_ACCESS);
CloseHandle(hInputWriteTmp);
CreatePipe(&hOutputReadTmp, &hOutputWrite, NULL, 0);
CreatePipe(&hOutputReadTmp, &hOutputWrite, &sa, 0);
DuplicateHandle(hp, hOutputReadTmp, hp, &hOutputRead, 0, FALSE, DUPLICATE_SAME_ACCESS);
CloseHandle(hOutputReadTmp);
if(spliterr) {
CreatePipe(&hErrorReadTmp, &hErrorWrite, NULL, 0);
CreatePipe(&hErrorReadTmp, &hErrorWrite, &sa, 0);
DuplicateHandle(hp, hErrorReadTmp, hp, &hErrorRead, 0, FALSE, DUPLICATE_SAME_ACCESS);
CloseHandle(hErrorReadTmp);
}
@ -167,15 +173,7 @@ bool LocalProcess::DoStart(const char *command, const Vector<String> *arg, bool
}
command = cmdh;
}
#if 0
int n = (int)strlen(command) + 1;
Buffer<char> cmd(n);
memcpy(cmd, command, n);
bool h = CreateProcess(NULL, cmd, NULL, NULL /*&sa, &sa*/, TRUE,
NORMAL_PRIORITY_CLASS, (void *)envptr, NULL, &si, &pi);
#else
bool h = Win32CreateProcess(command, envptr, si, pi);
#endif
LLOG("CreateProcess " << (h ? "succeeded" : "failed"));
CloseHandle(hErrorWrite);
CloseHandle(hInputRead);
@ -511,6 +509,8 @@ bool LocalProcess::Read2(String& reso, String& rese)
ReadFile(hErrorRead, buffer, sizeof(buffer), &n, NULL) && n)
rese.Cat(buffer, n);
DDUMPHEX(reso);
DDUMPHEX(rese);
if(convertcharset) {
reso = FromOEMCharset(reso);
rese = FromOEMCharset(rese);

45
uppsrc/ide/Upgrade.cpp Normal file
View file

@ -0,0 +1,45 @@
#include "ide.h"
void Ide::UpgradeTheIDE()
{
String idepath = GetExeFilePath();
String newpath = idepath + ".new";
String bakpath(~idepath, GetFileExtPos(idepath));
bakpath << ".bak.exe";
int tbak = targetmode;
String tmbak = StoreAsString(release);
release.target_override = true;
release.target = newpath;
#ifdef PLATFORM_WIN32
release.linkmode = 0;
#else
release.linkmode = 1;
#endif
release.createmap = false;
release.version.Clear();
release.def.blitz = false;
release.def.debug = false;
release.package.Clear();
targetmode = 1;
Clean();
if(!Build())
return;
FileDelete(bakpath);
if(FileExists(bakpath))
Exclamation("Unable to delete&" + bakpath);
else {
PutVerbose("Moving " + idepath + " to " + bakpath);
FileMove(idepath, bakpath);
PutVerbose("Moving " + newpath + " to " + idepath);
FileMove(newpath, idepath);
PutConsole("Upgrade finished, please restart theide.");
}
LoadFromString(release, tmbak);
targetmode = tbak;
}

View file

@ -903,6 +903,7 @@ public:
void SetUpdateTimer(int period);
void Abbreviations();
void DoMacroManager();
void UpgradeTheIDE();
void SetupMobilePlatforms(Bar& bar);
void SetupAndroidMobilePlatform(Bar& bar, const AndroidSDK& androidSDK);

View file

@ -85,6 +85,7 @@ file
Json.cpp,
MacroManager.cpp,
SetupSVN.cpp,
Upgrade.cpp,
Compile readonly separator,
MethodsCtrls.h,
MethodsCtrls.cpp,

View file

@ -394,6 +394,13 @@ void Ide::Setup(Bar& menu)
IdeAgain = true;
Break();
});
const Workspace& wspc = IdeWorkspace();
if(wspc[0] == "ide")
for(int i = 0; i < wspc.GetCount(); i++)
if(wspc[i] == "ide/Core")
menu.Add("Upgrade theide..", [=] { UpgradeTheIDE(); });
if(menu.IsMenuBar())
SetupMobilePlatforms(menu);
}