qt 打包 Qt Install Framework

C++11 多线程 汇总 - AcFun弹幕视频网

REG ADD "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\aftool-downloader\\config\\path" /v 记事本 /t REG_SZ /d "c:\windows\notepad.exe" /f

REG ADD "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV QML\\command" /v 记事本 /t REG_SZ /d "c:\windows\notepad.exe" /f

function Controller()

{

    //installer.installationFinished.connect(onInstalled)

    installer.uninstallationFinished.connect(function(){

      console.log("uninstall done")

      if (installer.value("os") === "win") {

          var unreg = "delete;HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open with QtAV;/f"

          var unreg2 = "delete;HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open with QtAV QML;/f"

          installer.executeDetached("reg", unreg.split(";"))

          installer.executeDetached("reg", unreg2.split(";"))

          //QMessageBox.information("", "finish", "unreg: " + unreg2.split(";"))

      }

    })

}

// 主动安装

,信息写入注册表

install.bat

reg add "HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with QtAV\command" /ve /t REG_SZ /d """"%~dp0bin\player.exe""" """-vo""" """gl""" """-f""" """%%1"""" /f

reg add "HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with QtAV QML\command" /ve /t REG_SZ /d """"%~dp0bin\QMLPlayer.exe""" """-f""" """%%1"""" /f

@echo Right click an video/music file, choose "Open with QtAV" to play

pause

// 主动卸载,信息写入注册表

uninstall.bat

reg delete "HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with QtAV" /f

reg delete "HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with QtAV QML" /f

pause

// 安装包安装 写入注册表

Component.prototype.createOperations = function()

{

    try {

        // call the base create operations function

        component.createOperations();

    } catch (e) {

        print(e);

    }

    if (installer.value("os") === "win") {

        component.addOperation("CreateShortcut", "@TargetDir@/bin/player.exe", "@StartMenuDir@/QtAV.Player.lnk",

            "workingDirectory=@TargetDir@/bin", "iconPath=@TargetDir@/bin/player.exe",

            "iconId=0");

        component.addOperation("CreateShortcut", "@TargetDir@/bin/QMLPlayer.exe", "@StartMenuDir@/QtAV.Player.QML.lnk",

            "workingDirectory=@TargetDir@/bin", "iconPath=@TargetDir@/bin/QMLPlayer.exe",

            "iconId=0");

        component.addOperation("CreateShortcut", "@TargetDir@/maintenancetool.exe", "@StartMenuDir@/QtAV.Uninstall.lnk",

            "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/maintenancetool.exe",

            "iconId=0");


        //component.addOperation("Settings", "formate=native", //"path=HKEY_CURRENT_USER/SOFTWARE/Classes/*/shell/OpenWithQtAV/command", "method=set", "key=Default", "value=@TargetDir@/bin/player.exe -vo  gl -f %%1");


        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV\\command", "Default", "\"@TargetDir@/bin/player.exe\" -vo gl -f \"%1\"");

        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV QML\\command", "Default", "\"@TargetDir@/bin/QMLPlayer.exe\" -f \"%1\"");

    }

}

// 安装包卸载 移除注册表

// config.xml

    QtAV

    1.12.0

    QtAV Multimedia framework

    WangBin [email protected]

    http://qtav.org

    ../../src/QtAV.png

    ../../src/QtAV

    ../../src/QtAV.png

   

    control.js

   

    true

   

    QtAV

    @rootDir@/QtAV

    @rootDir@/QtAV

    false

   

        zh_CN.qm

   

//control.js

function Controller()

{

    //installer.installationFinished.connect(onInstalled)

    installer.uninstallationFinished.connect(function(){

      console.log("uninstall done")

      if (installer.value("os") === "win") {

          var unreg = "delete;HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open with QtAV;/f"

          var unreg2 = "delete;HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open with QtAV QML;/f"

          installer.executeDetached("reg", unreg.split(";"))

          installer.executeDetached("reg", unreg2.split(";"))

          //QMessageBox.information("", "finish", "unreg: " + unreg2.split(";"))

      }

    })

}

Controller.prototype.LicenseAgreementPageCallback = function()

{

    var w = gui.currentPageWidget()

    if (w != null)

        w.AcceptLicenseRadioButton.checked = true

}



Component.prototype.createOperations =function()

{

// call default implementation to actually install files

component.createOperations();


if (systemInfo.productType === "windows") {

  install_runtime("2013", "12.0", 21005); // Note: 21005 displays as 30501

  install_runtime("2015-2019", "14.0", 29334);

}

delete_runtime("2013");

delete_runtime("2015-2019");

}


function install_runtime(vs_ver, major_subkey, build)

{

var executable = "vc" + vs_ver + "_vcredist_x64.exe";  // ie vc2013_vcredist_x64.exe

var runtime = "Microsoft Visual C++ " + vs_ver + " Runtime Bld " + build.toString();

var key = "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\" + major_subkey + "\\VC\\Runtimes\\x64"


// check if major version is installed

var installed = installer.execute("reg", new Array("QUERY", key, "/v", "Installed"))[0];

if (installed) {

  // check build number

  var bld = installer.execute("reg", new Array("QUERY", key, "/v", "Bld"))[0];

  var elements = bld.split(" ");

  bld = parseInt(elements[elements.length-1])

  var year_string = vs_ver

  if (year_string === "2015" || year_string === "2017") {

  // Note: both 2015 and 2017 use the 14.0 major subkey

  year_string = "2015/2017"

  }

  console.log("Found Microsoft Visual C++ " + year_string + " Runtime Bld " + bld.toString());

  if (bld < build) {

  console.log("Installing " + runtime + ": " + executable + " /quiet /norestart");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet", "/norestart");

  }

  else {

  console.log("No need to install " + runtime);

  }

}

else {

  console.log("Installing " + runtime + ": " + executable + " /quiet");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet");

}

}


function delete_runtime(vs_ver)

{

var executable = "vc" + vs_ver + "_vcredist_x64.exe";  // ie vc2013_vcredist_x64.exe

component.addOperation("Delete", "@TargetDir@/" + executable);

}



Component.prototype.createOperations = function()

{

    try {

        // call the base create operations function

component.createOperations();

    } catch (e) {

        print(e);

    }

    if (installer.value("os") === "win") {

        component.addOperation("CreateShortcut", "@TargetDir@/bin/player.exe", "@StartMenuDir@/QtAV.Player.lnk",

            "workingDirectory=@TargetDir@/bin", "iconPath=@TargetDir@/bin/player.exe",

            "iconId=0");

        component.addOperation("CreateShortcut", "@TargetDir@/bin/QMLPlayer.exe", "@StartMenuDir@/QtAV.Player.QML.lnk",

            "workingDirectory=@TargetDir@/bin", "iconPath=@TargetDir@/bin/QMLPlayer.exe",

            "iconId=0");

        component.addOperation("CreateShortcut", "@TargetDir@/maintenancetool.exe", "@StartMenuDir@/QtAV.Uninstall.lnk",

            "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/maintenancetool.exe",

            "iconId=0");

        //component.addOperation("Settings", "formate=native", //"path=HKEY_CURRENT_USER/SOFTWARE/Classes/*/shell/OpenWithQtAV/command", "method=set", "key=Default", "value=@TargetDir@/bin/player.exe -vo  gl -f %%1");


        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV\\command", "Default", "\"@TargetDir@/bin/player.exe\" -vo gl -f \"%1\"");

        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV QML\\command", "Default", "\"@TargetDir@/bin/QMLPlayer.exe\" -f \"%1\"");

    }

    if (installer.value("os") === "x11") {

        var d = "Type=Application\nComment=A media playing framework based on Qt and FFmpeg\nKeywords=movie;video;player;multimedia;\nIcon=QtAV\nTerminal=false\nHomepage=https://github.com/wang-bin/QtAV\nCategories=Qt;AudioVideo;Player;Video;Development;\nMimeType=application/mxf;application/ogg;application/ram;application/sdp;application/smil;application/smil+xml;application/vnd.ms-wpl;application/vnd.rn-realmedia;application/x-extension-m4a;application/x-extension-mp4;application/x-flac;application/x-flash-video;application/x-matroska;application/x-netshow-channel;application/x-ogg;application/x-quicktime-media-link;application/x-quicktimeplayer;application/x-shorten;application/x-smil;application/xspf+xml;audio/3gpp;audio/ac3;audio/AMR;audio/AMR-WB;audio/basic;audio/midi;audio/mp2;audio/mp4;audio/mpeg;audio/mpegurl;audio/ogg;audio/prs.sid;audio/vnd.rn-realaudio;audio/x-aiff;audio/x-ape;audio/x-flac;audio/x-gsm;audio/x-it;audio/x-m4a;audio/x-matroska;audio/x-mod;audio/x-mp3;audio/x-mpeg;audio/x-mpegurl;audio/x-ms-asf;audio/x-ms-asx;audio/x-ms-wax;audio/x-ms-wma;audio/x-musepack;audio/x-pn-aiff;audio/x-pn-au;audio/x-pn-realaudio;audio/x-pn-realaudio-plugin;audio/x-pn-wav;audio/x-pn-windows-acm;audio/x-realaudio;audio/x-real-audio;audio/x-sbc;audio/x-scpls;audio/x-speex;audio/x-tta;audio/x-wav;audio/x-wavpack;audio/x-vorbis;audio/x-vorbis+ogg;audio/x-xm;image/vnd.rn-realpix;image/x-pict;misc/ultravox;text/google-video-pointer;text/x-google-video-pointer;video/3gpp;video/dv;video/fli;video/flv;video/mp2t;video/mp4;video/mp4v-es;video/mpeg;video/msvideo;video/ogg;video/quicktime;video/vivo;video/vnd.divx;video/vnd.rn-realvideo;video/vnd.vivo;video/webm;video/x-anim;video/x-avi;video/x-flc;video/x-fli;video/x-flic;video/x-flv;video/x-m4v;video/x-matroska;video/x-mpeg;video/x-ms-asf;video/x-ms-asx;video/x-msvideo;video/x-ms-wm;video/x-ms-wmv;video/x-ms-wmx;video/x-ms-wvx;video/x-nsv;video/x-ogm+ogg;video/x-theora+ogg;video/x-totem-stream;x-content/video-dvd;x-content/video-vcd;x-content/video-svcd;x-scheme-handler/pnm;x-scheme-handler/mms;x-scheme-handler/net;x-scheme-handler/rtp;x-scheme-handler/rtsp;x-scheme-handler/mmsh;x-scheme-handler/uvox;x-scheme-handler/icy;x-scheme-handler/icyx;\nKeywords=Player;DVD;Audio;Video;";

        var player = "Name=QtAV Player\nGenericName=QtAV Player\nTryExec=@TargetDir@/bin/player.sh\nExec=@TargetDir@/bin/player.sh -f %U\n" + d;

        var qmlplayer = "Name=QtAV QMLPlayer\nGenericName=QtAV QMLPlayer\nTryExec=@TargetDir@/bin/QMLPlayer.sh\nExec=@TargetDir@/bin/QMLPlayer.sh -f %U\n" + d;

        component.addOperation("CreateDesktopEntry", "QtAV.Player.desktop", player);

        component.addOperation("CreateDesktopEntry", "QtAV.QMLPlayer.desktop", qmlplayer);

        component.addOperation("CreateDesktopEntry", "QtAV.Uninstall.desktop", "Name=QtAV Uninstall\nGenericName=QtAV Uninstall\nTryExec=@TargetDir@/uninstall\nExec=@TargetDir@/uninstall\nType=Application\nIcon=QtAV\nTerminal=false");

    }

}


        if (installer.value("os") == "win") {

            var settingsFile = installer.value("QtCreatorInstallerSettingsFile");

            if (settingsFile == "")

                return;

            component.addOperation("Settings", "path="+settingsFile, "method=add_array_value",

            "key=Plugins/ForceEnabled", "value=WinRt");

        }

 

  //component.addOperation("Settings", "formate=native", //"path=HKEY_CURRENT_USER/SOFTWARE/Classes/*/shell/OpenWithQtAV/command", "method=set", "key=Default", "value=@TargetDir@/bin/player.exe -vo  gl -f %%1");

        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV\\command", "Default", "\"@TargetDir@/bin/player.exe\" -vo gl -f \"%1\"");

        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV QML\\command", "Default", "\"@TargetDir@/bin/QMLPlayer.exe\" -f \"%1\"");

  component.addOperation("Settings", "formate=native", //"path=HKEY_CURRENT_USER/SOFTWARE/Classes/*/shell/OpenWithQtAV/command", "method=set", "key=Default", "value=@TargetDir@/bin/player.exe -vo  gl -f %%1");

 

        if( installer.value("os") === "win" )

        {

            /**

            * Cleanup AppData and registry

            */

            component.addElevatedOperation("Execute","UNDOEXECUTE","cmd /C reg delete HKEY_CURRENT_USER\Software\nheko\nheko /f");

            var localappdata = installer.environmentVariable("LOCALAPPDATA");

            if( localappdata != "" )

            {

                component.addElevatedOperation("Execute","UNDOEXECUTE","cmd /C rmdir "+localappdata+"\nheko /f");

            }

        }

 

  var key = "HKEY_CURRENT_USER\\Software\\Classes\\";

  var reg = installer.environmentVariable("SystemRoot") + "\\System32\\reg.exe";

  var key = "HKEY_CURRENT_USER\\Software\\Classes\\";

  var reg = installer.environmentVariable("SystemRoot") + "\\System32\\reg.exe";


  // Add registry key only if a key by same name does not already exist

  if (installer.execute(reg, new Array("QUERY", key))[1] !== 0)

  {

  component.addOperation("Execute", "{0,1}", reg, "ADD", key, "/ve", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key, "/ve", "/d", "URL:", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key, "/v", "URL Protocol", "/t", "REG_SZ", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key + "\\shell", "/ve", "/d", "open", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key + "\\shell\\open", "/f");

component.addOperation("Execute", "{0,1}", reg, "ADD", key + "\\shell\\open\\command", "/ve", "/t", "REG_SZ", "/d", "\"@TargetDir@\\RiverReaches.exe\" \"%1\"", "/f");

  component.addOperation("Execute", "{0,1}", reg, "QUERY", key, "UNDOEXECUTE", "{0,1}", reg, "DELETE", key, "/f");

  }

 


boolean uninstallationRequested()

Determines whether the user wants to uninstall the component.



bool

uninstallationRequested() const




uninstallationFinished()


function reactOnAbortInstallerChange()

{

    if (installer.value("ComponentError") === "true")

 

    abortInstaller();// 中断安装

}


// 读取注册表

function install_runtime(vs_ver, major_subkey, build)

{

var executable = "vc" + vs_ver + "_vcredist_x64.exe";  // ie vc2013_vcredist_x64.exe

var runtime = "Microsoft Visual C++ " + vs_ver + " Runtime Bld " + build.toString();

var key = "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\" + major_subkey + "\\VC\\Runtimes\\x64"


// check if major version is installed

var installed = installer.execute("reg", new Array("QUERY", key, "/v", "Installed"))[0];

if (installed) {

  // check build number

  var bld = installer.execute("reg", new Array("QUERY", key, "/v", "Bld"))[0];

  var elements = bld.split(" ");

  bld = parseInt(elements[elements.length-1])

  var year_string = vs_ver

  if (year_string === "2015" || year_string === "2017") {

  // Note: both 2015 and 2017 use the 14.0 major subkey

  year_string = "2015/2017"

  }

  console.log("Found Microsoft Visual C++ " + year_string + " Runtime Bld " + bld.toString());

  if (bld < build) {

  console.log("Installing " + runtime + ": " + executable + " /quiet /norestart");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet", "/norestart");

  }

  else {

  console.log("No need to install " + runtime);

  }

}

else {

  console.log("Installing " + runtime + ": " + executable + " /quiet");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet");

}

}

function reactOnAbortInstallerChange()

{

    if (installer.value("ComponentError") === "true")

        abortInstaller();// 中断安装

}



function Component()

{

    var error = true;

    if (error) {

        installer.setValue("component_errors", installer.value("component_errors") + ";;;"

            + "Error in component: " + component.name);

    }

    installer.setValue("ComponentError", true);

}

// 读取注册表

function install_runtime(vs_ver, major_subkey, build)

{

var executable = "vc" + vs_ver + "_vcredist_x64.exe";  // ie vc2013_vcredist_x64.exe

var runtime = "Microsoft Visual C++ " + vs_ver + " Runtime Bld " + build.toString();

var key = "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\" + major_subkey + "\\VC\\Runtimes\\x64"


// check if major version is installed

var installed = installer.execute("reg", new Array("QUERY", key, "/v", "Installed"))[0];

if (installed) {

  // check build number

  var bld = installer.execute("reg", new Array("QUERY", key, "/v", "Bld"))[0];

  var elements = bld.split(" ");

  bld = parseInt(elements[elements.length-1])

  var year_string = vs_ver

  if (year_string === "2015" || year_string === "2017") {

  // Note: both 2015 and 2017 use the 14.0 major subkey

  year_string = "2015/2017"

  }

  console.log("Found Microsoft Visual C++ " + year_string + " Runtime Bld " + bld.toString());

  if (bld < build) { // 现有的版本低于需要安装编译的版本,则安装新版本

  console.log("Installing " + runtime + ": " + executable + " /quiet /norestart");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet", "/norestart");

  }

  else { // 现有的版本高于或与需要安装的版本相同,则提示不需要安装

  console.log("No need to install " + runtime);

  }

}

else { // 没有安装过,则安装新版本

  console.log("Installing " + runtime + ": " + executable + " /quiet");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet");

}

}

function Component()

{

    gui.pageWidgetByObjectName("LicenseAgreementPage").entered.connect(changeLicenseLabels);

}

changeLicenseLabels = function()

{

    page = gui.pageWidgetByObjectName("LicenseAgreementPage"); // 获取gui模块中的某对象

    page.AcceptLicenseLabel.setText("Yes I do!"); //找到gui模块中的LicenseAgreementPage页面,并设置该页面总的相应Label的Text

    page.RejectLicenseLabel.setText("No I don't!");

}

function Component()

{

    // 当gui模块进入到LicenseAgreementPage这个页面的时候,相应changeLicenseLabels函数

    gui.pageWidgetByObjectName("LicenseAgreementPage").entered.connect(changeLicenseLabels);

}


changeLicenseLabels = function()

{

    page = gui.pageWidgetByObjectName("LicenseAgreementPage"); // 获取gui模块中的某对象

    page.AcceptLicenseLabel.setText("Yes I do!"); //找到gui模块中的LicenseAgreementPage页面,并设置该页面总的相应Label的Text

    page.RejectLicenseLabel.setText("No I don't!");

}

function abortInstaller()

{

// 安装器模块让所有相关的安装页面不可见

    installer.setDefaultPageVisible(QInstaller.Introduction, false);

    installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);

    installer.setDefaultPageVisible(QInstaller.ComponentSelection, false);

    installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false);

    installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false);

    installer.setDefaultPageVisible(QInstaller.PerformInstallation, false);

    installer.setDefaultPageVisible(QInstaller.LicenseCheck, false);


    var abortText = "" + qsTr("Installation failed:") + "";


    var error_list = installer.value("component_errors").split(";;;");

    abortText += "

    ";

        // ignore the first empty one

        for (var i = 0; i < error_list.length; ++i) {

            if (error_list[i] !== "") {

                console.log(error_list[i]);

                abortText += "

  • " + error_list[i] + "
  • "

            }

        }

        abortText += "

";

// 安装器设置完成页面显示信息

    installer.setValue("FinishedText", abortText);

}


function reactOnAbortInstallerChange()

{

// 安装器模块检测到有错误则执行abortInstaller函数

    if (installer.value("ComponentError") === "true")

        abortInstaller();

}


function Component()

{

// 安装器模块完成所有组件初始化时,调用reactOnAbortInstallerChange函数

    installer.finishAllComponentsReset.connect(reactOnAbortInstallerChange);

}

REG ADD "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\aftool-downloader\\config\\path" /v 记事本 /t REG_SZ /d "c:\windows\notepad.exe" /f

REG ADD "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV QML\\command" /v 记事本 /t REG_SZ /d "c:\windows\notepad.exe" /f


function Controller()

{

    //installer.installationFinished.connect(onInstalled)

    installer.uninstallationFinished.connect(function(){

      console.log("uninstall done")

      if (installer.value("os") === "win") {

          var unreg = "delete;HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open with QtAV;/f"

          var unreg2 = "delete;HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open with QtAV QML;/f"

          installer.executeDetached("reg", unreg.split(";"))

          installer.executeDetached("reg", unreg2.split(";"))

          //QMessageBox.information("", "finish", "unreg: " + unreg2.split(";"))

      }

    })

}


// 主动安装,信息写入注册表

install.bat

reg add "HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with QtAV\command" /ve /t REG_SZ /d """"%~dp0bin\player.exe""" """-vo""" """gl""" """-f""" """%%1"""" /f

reg add "HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with QtAV QML\command" /ve /t REG_SZ /d """"%~dp0bin\QMLPlayer.exe""" """-f""" """%%1"""" /f

@echo Right click an video/music file, choose "Open with QtAV" to play

pause

// 主动卸载,信息写入注册表

uninstall.bat

reg delete "HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with QtAV" /f

reg delete "HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with QtAV QML" /f

pause



// 安装包安装 写入注册表

Component.prototype.createOperations = function()

{

    try {

        // call the base create operations function

        component.createOperations();

    } catch (e) {

        print(e);

    }


    if (installer.value("os") === "win") {

        component.addOperation("CreateShortcut", "@TargetDir@/bin/player.exe", "@StartMenuDir@/QtAV.Player.lnk",

            "workingDirectory=@TargetDir@/bin", "iconPath=@TargetDir@/bin/player.exe",

            "iconId=0");

        component.addOperation("CreateShortcut", "@TargetDir@/bin/QMLPlayer.exe", "@StartMenuDir@/QtAV.Player.QML.lnk",

            "workingDirectory=@TargetDir@/bin", "iconPath=@TargetDir@/bin/QMLPlayer.exe",

            "iconId=0");

        component.addOperation("CreateShortcut", "@TargetDir@/maintenancetool.exe", "@StartMenuDir@/QtAV.Uninstall.lnk",

            "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/maintenancetool.exe",

            "iconId=0");


        //component.addOperation("Settings", "formate=native", //"path=HKEY_CURRENT_USER/SOFTWARE/Classes/*/shell/OpenWithQtAV/command", "method=set", "key=Default", "value=@TargetDir@/bin/player.exe -vo  gl -f %%1");


        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV\\command", "Default", "\"@TargetDir@/bin/player.exe\" -vo gl -f \"%1\"");

        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV QML\\command", "Default","\"@TargetDir@/bin/QMLPlayer.exe\" -f \"%1\"");

    }

}

// 安装包卸载 移除注册表

// config.xml

    QtAV

    1.12.0

    QtAV Multimedia framework

    WangBin [email protected]

    http://qtav.org

    ../../src/QtAV.png

    ../../src/QtAV

    ../../src/QtAV.png

   

    control.js

   

    true

   

    QtAV

    @rootDir@/QtAV

    @rootDir@/QtAV

    false

   

        zh_CN.qm

  year_string = "2015/2017"

  }

  console.log("Found Microsoft Visual C++ " + year_string + " Runtime Bld " + bld.toString());

  if (bld < build) {

  console.log("Installing " + runtime + ": " + executable + " /quiet /norestart");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet", "/norestart");

  }

  else {

  console.log("No need to install " + runtime);

  }

}

else {

  console.log("Installing " + runtime + ": " + executable + " /quiet");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet");

}

}


function delete_runtime(vs_ver)

{

var executable = "vc" + vs_ver + "_vcredist_x64.exe";  // ie vc2013_vcredist_x64.exe

component.addOperation("Delete", "@TargetDir@/" + executable);

}



Component.prototype.createOperations = function()

{

    try {

        // call the base create operations function

        component.createOperations();

    } catch (e) {

        print(e);

    }


    if (installer.value("os") === "win") {

        component.addOperation("CreateShortcut", "@TargetDir@/bin/player.exe", "@StartMenuDir@/QtAV.Player.lnk",

            "workingDirectory=@TargetDir@/bin", "iconPath=@TargetDir@/bin/player.exe",

            "iconId=0");

        component.addOperation("CreateShortcut", "@TargetDir@/bin/QMLPlayer.exe", "@StartMenuDir@/QtAV.Player.QML.lnk",

            "workingDirectory=@TargetDir@/bin", "iconPath=@TargetDir@/bin/QMLPlayer.exe",

            "iconId=0");

        component.addOperation("CreateShortcut", "@TargetDir@/maintenancetool.exe", "@StartMenuDir@/QtAV.Uninstall.lnk",

            "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/maintenancetool.exe",

            "iconId=0");


        //component.addOperation("Settings", "formate=native", //"path=HKEY_CURRENT_USER/SOFTWARE/Classes/*/shell/OpenWithQtAV/command", "method=set", "key=Default", "value=@TargetDir@/bin/player.exe -vo  gl -f %%1");


        component.addOperation("GlobalConfig", "HKEY_Cslation>

   

//control.js

function Controller()

{

    //installer.installationFinished.connect(onInstalled)

    installer.uninstallationFinished.connect(function(){

      console.log("uninstall done")

      if (installer.value("os") === "win") {

          var unreg = "delete;HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open with QtAV;/f"

          var unreg2 = "delete;HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open with QtAV QML;/f"

          installer.executeDetached("reg", unreg.split(";"))

          installer.executeDetached("reg", unreg2.split(";"))

          //QMessageBox.information("", "finish", "unreg: " + unreg2.split(";"))

      }

    })

}

Controller.prototype.LicenseAgreementPageCallback = function()

{

    var w = gui.currentPageWidget()

    if (w != null)

        w.AcceptLicenseRadioButton.checked = true

}



Component.prototype.createOperations = function()

{

// call default implementation to actually install files

component.createURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV\\command", "Default", "\"@TargetDir@/bin/player.exe\" -vo gl -f \"%1\"");

        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV QML\\command", "Default", "\"@TargetDir@/bin/QMLPlayer.exe\" -f \"%1\"");

    }

    if (installer.value("os") === "x11") {

        var d = "Type=Application\nComment=A media playing framework based on Qt and FFmpeg\nKeywords=movie;video;player;multimedia;\nIcon=QtAV\nTerminal=false\nHomepage=https://github.com/wang-bin/QtAV\nCategories=Qt;AudioVideo;Player;Video;Development;\nMimeType=application/mxf;application/ogg;application/ram;application/sdp;application/smil;application/smil+xml;application/vnd.ms-wpl;application/vnd.rn-realmedia;application/x-extension-m4a;application/x-extension-mp4;application/x-flac;application/x-flash-video;application/x-matroska;application/x-netshow-channel;application/x-ogg;application/x-quicktime-media-link;applicato/vnd.rn-realvideo;video/vnd.vivo;video/webm;video/x-anim;video/x-avi;video/x-flc;video/x-fli;video/x-flic;video/x-flv;video/x-m4v;video/x-matroska;video/x-mpeg;video/x-ms-asf;video/x-ms-asx;video/x-msvideo;video/x-ms-wm;video/x-ms-wmv;video/x-ms-wmx;video/x-ms-wvx;video/x-nsv;video/x-ogm+ogg;video/x-theora+ogg;video/x-totem-stream;x-content/video-dvd;x-content/video-vcd;x-content/video-svcd;x-scheme-handler/pnm;x-scheme-handler/mms;x-scheme-handler/net;x-scheme-handler/rtp;x-scheme-handler/rtsp;x-scheme-handler/mmsh;x-scheme-handler/uvox;x-scheme-handler/icy;x-scheme-handler/icyx;\nKeywords=Player;DVD;Audio;Video;";

        var player = "Name=QtAV Player\nGenericName=QtAV Player\nTryExec=@TargetDir@/bin/player.sh\nExec=@TargetDir@/bin/player.sh -f %U\n" + d;

        var qmlplayer = "Name=QtAV QMLPlayer\nGenericName=QtAV QMLPlayer\nTryExec=@TargetDir@/bin/QMLPlayer.sh\nExec=@TargetDir@/bin/QMLPlayer.sh -f %U\n" + d;

        component.addOperation("CreateDesktopEntry", "QtAV.Player.desktop", player);

        component.addOperation("CreateDesktopEntry", "QtAV.QMLPlayer.desktop", qmlplayer);

        component.addOperation("CreateDesktopEntry", "QtAV.Uninstall.desktop", "Name=QtAV Uninstall\nGenericName=QtAV Uninstall\nTryExec=@TargetDir@/uninstall\nExec=@TargetDir@/uninstall\nType=Application\nIcon=QtAV\nTerminal=false");

    }

}


        if (installer.value("os") == "win") {

            var settingsFile = installer.value("QtCreatorInstallerSettingsFile");

            if (settingsFile == "")

                return;

            component.addOperation("Settings", "path="+settingsFile, "method=add_array_value",

            "key=Plugins/ForceEnabled", "value=WinRt");

        }

 

  //component.addOperation("Settings", "formate=native", //"path=HKEY_CURRENT_USER/SOFTWARE/Classes/*/shell/OpenWithQtAV/command", "method=set", "key=Default", "value=@TargetDir@/bin/player.exe -vo  gl -f %%1");

        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV\\command", "Default", "\"@TargetDir@/bin/player.exe\" -vo gl -f \"%1\"");

        component.addOperation("GlobalConfig", "HKEY_CURRENT_USER\\SOFTWARE\\Classes\\*\\shell\\Open With QtAV QML\\command", "Default", "\"@TargetDir@/bin/QMLPlayer.exe\" -f \"%1\"");

  component.addOperation("Settings", "formate=native", //"path=HKEY_CURRENT_USER/SOFTWARE/Classes/*/shell/OpenWithQtAV/command", "method=set", "key=Default", "value=@TargetDir@/bin/player.exe -vo  gl -f %%1");

 

        if( installer.value("os") === "win" )

        {

            /**

            * Cleanup AppData and registry

            */

            component.addElevatedOperation("Execute","UNDOEXECUTE","cmd /C reg delete HKEY_CURRENT_USER\Software\nheko\nheko /f");

            var localappdata = installer.environmentVariable("LOCALAPPDATA");

            if( localappdata != "" )

            {

                component.addElevatedOperation("Execute","UNDOEXECUTE","cmd /C rmdir "+localappdata+"\nheko /f");

            }

        }

 

  var key = "HKEY_CURRENT_USER\\Software\\Classes\\";

  var reg = installer.environmentVariable("SystemRoot") + "\\System32\\reg.exe";

  var key = "HKEY_CURRENT_USER\\Software\\Classes\\";

  var reg = installer.environmentVariable("SystemRoot") + "\\System32\\reg.exe";


  // Add registry key only if a key by same name does not already exist

  if (installer.execute(reg, new Array("QUERY", key))[1] !== 0)

  {

  component.addOperation("Execute", "{0,1}", reg, "ADD", key, "/ve", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key, "/ve", "/d", "URL:", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key, "/v", "URL Protocol", "/t", "REG_SZ", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key + "\\shell", "/ve", "/d", "open", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key + "\\shell\\open", "/f");

  component.addOperation("Execute", "{0,1}", reg, "ADD", key + "\\shell\\open\\command", "k build number

  var bld = installer.execute("reg", new Array("QUERY", key, "/v", "Bld"))[0];

  var elements = bld.split(" ");

  bld = parseInt(elements[elements.length-1])

  var year_string = vs_ver

  if (year_string === "2015" || year_string === "2017") {

  // Note: both 2015 and 2017 use the 14.0 major subkey

  year_string = "2015/2017"

  }

  console.log("Found Microsoft Visual C++ " + year_string + " Runtime Bld " + bld.toString());

  if (bld < build) { // 现有的版本低于需要安装编译的版本,则安装新版本

  console.log("Installing " + runtime + ": " + executable + " /quiet /norestart");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet", "/norestart");

  }

  else { // 现有的版本高于或与需要安装的版本相同,则提示不需要安装

  console.log("No need to install " + runtime);

  }

}

else { // 没有安装过,则安装新版本

  console.log("Installing " + runtime + ": " + executable + " /quiet");

  component.addOperation("Execute", "@TargetDir@/" + executable, "/quiet");

}

}



function Component()

{

    // 当gui模块进入到LicenseAgreement

/ve", "/t", "REG_SZ", "/d", "\"@TargetDir@\\RiverReaches.exe\" \"%1\"", "/f");

  component.addOperation("Execute", "{0,1}", reg, "QUERY", key, "UNDOEXECUTE", "{0,1}", reg, "DELETE", key, "/f");

  }

 


boolean uninstallationRequested()

Determines whether the user wants to uninstall the component.



bool

uninstallationRequested() const




uninstallationFinished()


function reactOnAbortInstallerChange()

{

    if (installer.value("ComponentError") === "true")

 

    abortInstaller();// 中断安装

}


// 读取注册表

function install_runtime(vs_ver, major_subkey, build)

{

var executable = "vc" + vs_ver + "_vcredist_x64.exe";  // ie vc2013_vcredist_x64.exe

var runtime = "Microsoft Visual C++ " + vs_ver + " Runtime Bld " + build.toString();

var key = "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\" + major_subkey + "\\VC\\Runtimes\\x64"


// check if major version is installed

var installed = installer.execute("reg", new Array("QUERY", key, "/v", "Installed"))[0];

if (installed) {

  // checPage这个页面的时候,相应changeLicenseLabels函数

    gui.pageWidgetByObjectName("LicenseAgreementPage").entered.connect(changeLicenseLabels);

}


changeLicenseLabels = function()

{

    page = gui.pageWidgetByObjectName("LicenseAgreementPage"); // 获取gui模块中的某对象

    page.AcceptLicenseLabel.setText("Yes I do!"); //找到gui模块中的LicenseAgreementPage页面,并设置该页面总的相应Label的Text

    page.RejectLicenseLabel.setText("No I don't!");

}


function abortInstaller()

{

// 安装器模块让所有相关的安装页面不可见

    installer.setDefaultPageVisible(QInstaller.Introduction, false);

    installer.setDefaultPageVisible(QInstaller.TargetDirectory, false);

    installer.setDefaultPageVisible(QInstaller.ComponentSelection, false);

    installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false);

    installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false);

    installer.setDefaultPageVisible(QInstaller.PerformInstallation, false);

    installer.setDefaultPageVisible(QInstaller.LicenseCheck, false);


    var abortText = "" + qsTr("Installation failed:") + "";


    var error_list = installer.value("component_errors").split(";;;");

    abortText += "

    ";

        // ignore the first empty one

        for (var i = 0; i < error_list.length; ++i) {

            if (error_list[i] !== "") {

                console.log(error_list[i]);

                abortText += "

  • " + error_list[i] + "
  • "

            }

        }

        abortText += "

";

// 安装器设置完成页面显示信息

    installer.setValue("FinishedText", abortText);

}


function reactOnAbortInstallerChange()

{

// 安装器模块检测到有错误则执行abortInstaller函数

    if (installer.value("ComponentError") === "true")

        abortInstaller();

}


function Component()

{

// 安装器模块完成所有组件初始化时,调用reactOnAbortInstallerChange函数

    installer.finishAllComponentsReset.connect(reactOnAbortInstallerChange);

}





function Component()

{

    var error = true;

    if (error) {

        installer.setValue("component_errors", installer.value("component_errors") + ";;;"

            + "Error in component: " +component.name);

    }

    installer.setValue("ComponentError", true); // 设置安装器模块ComponentError的值为true

}


Component.prototype.installationFinished = function()

{

    try {

        if (installer.isInstaller() && installer.status == QInstaller.Success) {

            var checkboxForm = component.userInterface( "ReadMeCheckBoxForm" ); // 调用用户接口

            if (checkboxForm && checkboxForm.readMeCheckBox.checked) {

                QDesktopServices.openUrl("file:///" + installer.value("TargetDir") + "/README.txt");

            }

        }

    } catch(e) {

        console.log(e);

    }

}

你可能感兴趣的:(qt 打包 Qt Install Framework)