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

<?xml version="1.0" encoding="UTF-8"?>

<Installer>

    <Name>QtAV</Name>

    <Version>1.12.0</Version>

    <Title>QtAV Multimedia framework</Title>

    <Publisher>WangBin wbsecg1@gmail.com</Publisher>

    <ProductUrl>http://qtav.org</ProductUrl>

    <Logo>../../src/QtAV.png</Logo>

    <InstallerApplicationIcon>../../src/QtAV</InstallerApplicationIcon>

    <InstallerWindowIcon>../../src/QtAV.png</InstallerWindowIcon>

    <Watermark></Watermark>

    <ControlScript>control.js</ControlScript>

    <RunProgramDescription></RunProgramDescription>

    <AllowNonAsciiCharacters>true</AllowNonAsciiCharacters>

    <Background></Background>

    <StartMenuDir>QtAV</StartMenuDir>

    <TargetDir>@rootDir@/QtAV</TargetDir>

    <AdminTargetDir>@rootDir@/QtAV</AdminTargetDir>

    <RepositorySettingsPageVisible>false</RepositorySettingsPageVisible>

    <Translations>

        <Translation>zh_CN.qm</Translation>

    </Translations>

</Installer>

//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 = "<font color='red' size=3>" + qsTr("Installation failed:") + "</font>";


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

    abortText += "<ul>";

    // ignore the first empty one

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

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

            console.log(error_list[i]);

            abortText += "<li>" + error_list[i] + "</li>"

        }

    }

    abortText += "</ul>";

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

    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

<?xml version="1.0" encoding="UTF-8"?>

<Installer>

    <Name>QtAV</Name>

    <Version>1.12.0</Version>

    <Title>QtAV Multimedia framework</Title>

    <Publisher>WangBin wbsecg1@gmail.com</Publisher>

    <ProductUrl>http://qtav.org</ProductUrl>

    <Logo>../../src/QtAV.png</Logo>

    <InstallerApplicationIcon>../../src/QtAV</InstallerApplicationIcon>

    <InstallerWindowIcon>../../src/QtAV.png</InstallerWindowIcon>

    <Watermark></Watermark>

    <ControlScript>control.js</ControlScript>

    <RunProgramDescription></RunProgramDescription>

    <AllowNonAsciiCharacters>true</AllowNonAsciiCharacters>

    <Background></Background>

    <StartMenuDir>QtAV</StartMenuDir>

    <TargetDir>@rootDir@/QtAV</TargetDir>

    <AdminTargetDir>@rootDir@/QtAV</AdminTargetDir>

    <RepositorySettingsPageVisible>false</RepositorySettingsPageVisible>

    <Translations>

        <Translation>zh_CN.qm</TranNote: 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_Cslation>

    </Translations>

</Installer>

//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 = "<font color='red' size=3>" + qsTr("Installation failed:") + "</font>";


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

    abortText += "<ul>";

    // ignore the first empty one

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

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

            console.log(error_list[i]);

            abortText += "<li>" + error_list[i] + "</li>"

        }

    }

    abortText += "</ul>";

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

    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);

    }

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,692评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,482评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,995评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,223评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,245评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,208评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,091评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,929评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,346评论 1 311
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,570评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,739评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,437评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,037评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,677评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,833评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,760评论 2 369
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,647评论 2 354

推荐阅读更多精彩内容