From 2f1584025717c27acc98b90d2a2e4d850317e4bb Mon Sep 17 00:00:00 2001 From: kichik Date: Sat, 16 Sep 2006 13:38:21 +0000 Subject: [PATCH] moved manifest generation to a seprate file and added made it support vista's access level extensions git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4751 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/SConscript | 1 + Source/build.cpp | 27 ++++++++++++++++++++++++++ Source/build.h | 5 +++++ Source/manifest.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++ Source/manifest.h | 24 +++++++++++++++++++++++ Source/script.cpp | 13 +++++-------- 6 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 Source/manifest.cpp create mode 100644 Source/manifest.h diff --git a/Source/SConscript b/Source/SConscript index 1c45b57a..667e1832 100644 --- a/Source/SConscript +++ b/Source/SConscript @@ -13,6 +13,7 @@ makensis_files = Split(""" lang.cpp lineparse.cpp makenssi.cpp + manifest.cpp mmap.cpp Plugins.cpp ResourceEditor.cpp diff --git a/Source/build.cpp b/Source/build.cpp index a1d48afc..3335f7f3 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -9,6 +9,7 @@ #include "fileform.h" #include "writer.h" #include "crc32.h" +#include "manifest.h" #include @@ -226,6 +227,9 @@ CEXEBuild::CEXEBuild() : res_editor=0; + manifest_comctl = manifest::comctl_old; + manifest_exec_level = manifest::exec_level_none; + enable_last_page_cancel=0; uenable_last_page_cancel=0; @@ -2113,6 +2117,26 @@ int CEXEBuild::SetVarsSection() return PS_OK; } +int CEXEBuild::SetManifest() +{ + try { + init_res_editor(); + + string manifest = manifest::generate(manifest_comctl, manifest_exec_level); + + if (manifest == "") + return PS_OK; + + res_editor->UpdateResource(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), NSIS_DEFAULT_LANG, (LPBYTE) manifest.c_str(), manifest.length()); + } + catch (exception& err) { + ERROR_MSG("Error while setting manifest: %s\n", err.what()); + return PS_ERROR; + } + + return PS_OK; +} + int CEXEBuild::check_write_output_errors() const { if (has_called_write_output) @@ -2273,6 +2297,9 @@ int CEXEBuild::write_output(void) // Setup user variables PE section RET_UNLESS_OK( SetVarsSection() ); + // Set XML manifest + RET_UNLESS_OK( SetManifest() ); + try { // Save all changes to the exe header close_res_editor(); diff --git a/Source/build.h b/Source/build.h index 824ec86c..5cbf8616 100644 --- a/Source/build.h +++ b/Source/build.h @@ -9,6 +9,7 @@ #include "uservars.h" #include "ShConstants.h" #include "mmap.h" +#include "manifest.h" #include "exehead/fileform.h" #include "exehead/config.h" @@ -217,6 +218,7 @@ class CEXEBuild { void PrepareInstTypes(); void PrepareHeaders(IGrowBuf *hdrbuf); int SetVarsSection(); + int SetManifest(); int resolve_jump_int(const char *fn, int *a, int offs, int start, int end); int resolve_call_int(const char *fn, const char *str, int fptr, int *ofs); @@ -375,6 +377,9 @@ class CEXEBuild { int deflateToFile(FILE *fp, char *buf, int len); // len==0 to flush #endif + manifest::comctl manifest_comctl; + manifest::exec_level manifest_exec_level; + CResourceEditor *res_editor; void init_res_editor(); void close_res_editor(); diff --git a/Source/manifest.cpp b/Source/manifest.cpp new file mode 100644 index 00000000..9864593e --- /dev/null +++ b/Source/manifest.cpp @@ -0,0 +1,46 @@ +#include "Platform.h" +#include "manifest.h" +#include "version.h" + +namespace manifest +{ + +using namespace std; + +string generate(comctl comctl_selection, exec_level exec_level_selection) +{ + if (comctl_selection == comctl_old && exec_level_selection == exec_level_none) + return ""; + + string xml = "Nullsoft Install System " NSIS_VERSION ""; + + if (comctl_selection == comctl_xp) + { + xml += ""; + } + + if (exec_level_selection != exec_level_none) + { + string level = ""; + + switch (exec_level_selection) + { + case exec_level_user: + level = "asInvoker"; + break; + case exec_level_admin: + level = "requireAdministrator"; + break; + } + + xml += ""; + } + + xml += ""; + + return xml; +} + +}; diff --git a/Source/manifest.h b/Source/manifest.h new file mode 100644 index 00000000..a859c536 --- /dev/null +++ b/Source/manifest.h @@ -0,0 +1,24 @@ +#ifndef ___MANIFEST_H___ +#define ___MANIFEST_H___ + +#include + +namespace manifest +{ + enum comctl + { + comctl_old, + comctl_xp + }; + + enum exec_level + { + exec_level_none, + exec_level_user, + exec_level_admin + }; + + std::string generate(comctl, exec_level); +}; + +#endif//!___MANIFEST_H___ diff --git a/Source/script.cpp b/Source/script.cpp index 48b060dc..6871c052 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -2332,17 +2332,14 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } return PS_OK; case TOK_XPSTYLE: - try { + { int k=line.gettoken_enum(1,"on\0off\0"); if (k == -1) PRINTHELP() SCRIPT_MSG("XPStyle: %s\n", line.gettoken_str(1)); - init_res_editor(); - const char *szXPManifest = k ? 0 : "Nullsoft Install System " NSIS_VERSION ""; - res_editor->UpdateResource(MAKEINTRESOURCE(24), MAKEINTRESOURCE(1), NSIS_DEFAULT_LANG, (unsigned char*)szXPManifest, k ? 0 : strlen(szXPManifest)); - } - catch (exception& err) { - ERROR_MSG("Error while adding XP style: %s\n", err.what()); - return PS_ERROR; + if (!k) + manifest_comctl = manifest::comctl_xp; + else + manifest_comctl = manifest::comctl_old; } return PS_OK; case TOK_CHANGEUI: