0

I'm creating an installer and I need to have functionality to read a text file and get some installation params. Specifically, I need to read an installation path from a text file. I was trying to use FileReader from JS, but I can't figure out how it could be used inside the Controller.prototype.TargetDirectoryPageCallback function. Maybe there is easier approach to do that? Any working sample maybe?

Glen Selle
  • 3,966
  • 4
  • 37
  • 59
Robert
  • 214
  • 1
  • 9

2 Answers2

1

The script context has only a few objects.

  • console
  • QFileDialog
  • print
  • qsTr
  • systemInfo
  • QInstaller
  • buttons
  • QMessageBox
  • QDesktopServices
  • installer
  • gui

The "installer" object is the most important one (see http://doc.qt.io/qtinstallerframework/scripting-installer.html#execute-method). With the help of this execute method you can run any application on your system. So here my untested code suggestion:

if (installer.value("os") == "win") {
  var windir = installer.environmentVariable("WINDIR");
  if (windir == "")
    print("Could not find windows installation directory.");
  var cmdLocation = windir + "\\system32\\cmd.exe";
var fileContent = installer.execute(cmdLocation, new Array("/c", "type", <your_file>))[0];

Yes this is not very comfortable - so maybe you should create a feature request or add this kind of functionality to the installer framework.

Tim Jenßen
  • 903
  • 6
  • 5
1

Qt Installer Framework 3.x:

string readFile(string filePath, string codecName)

Denys Rogovchenko
  • 191
  • 1
  • 2
  • 7