wsh currentdirectory broken on Win 8.1? - hta

We use HTA files to build installation CD's, so that we can display some introductory information and links to different setup options - each link goes to the appropriate setup.exe etc file. This has worked fine up to and including Windows 7, but on 8.1 (- not tried 8.0) it fails with an error 'Cannot find the file specified'. Turns out that this is because the current directory is now C:\Windows\System32, whereas it used to be the directory where the file was located - on the CD drive, and so relative paths would work for the links to the other files on the CD; now they don't.
In other words using this code in an hta file:
<script type="text/javascript" language="javascript">
function RunFile(appname)
{
WshShell = new ActiveXObject("WScript.Shell");
alert( WshShell.CurrentDirectory );
WshShell.Run(appname, 1, false);
}
on win 8.1 we see C:\Windows\System32 in the alert box and so relative paths such as ..\ourproduct\setup.exe no longer work.
Is this a bug? Any ideas how I can work around this?

You could extract the correct path from window.location.pathname, and then set the value to CurrentDirectory. I've used something like the code below:
var shell = new ActiveXObject('WScript.Shell'),
defaultInstallationFolder = 'installation_folder_name',
currentPath = window.location.pathname.replace(/\\/g,'/'),
defaultRootPath;
if (currentPath.charAt(0) === '/') { // For the browser environment
currentPath = currentPath.substring(1, currentPath.length);
}
currentPath = currentPath.split(defaultInstallationFolder);
defaultRootPath = currentPath[0] + defaultInstallationFolder;
shell.CurrentDirectory = defaultRootPath;
IE and HTA give a slightly different pathname (in IE it starts with /). Sometimes it's nice to debug a HTA in IE, hence the check for currentPath.

Related

Lightswitch HTML - chat application upgrade

I wanted to know if anyone has given this a go and got it working?
http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/182/Connecting-To-SignalR-With-LightSwitch-HTML-Client.aspx
Basically my issue is i cant open the file to begin with, whether it be Visual Studio 2012, 2013 or 2015, so I have followed the guide and used the files from the downloaded project for this error message to occur:
which is caused by this line under the sendmessage_execute function:
chat.server.send(screen.displayname, screen.message);
im hoping someone has got this working and could point out anything different from the user guide, heres what I have used/done:
Under the PROJECT.Server I have:
created a folder called SignalR with the file ChatHub.cs in
added the json2.js (both) and signalR (both) files to the scripts
folder
Under the Project.HTMLClient
added the json2.js (both) and signalR (both) files to the scripts
folder
referenced the scripts including the localhost in the default.htm file
Created a screen. called ChatScreen and added all the referenced code here from the guide online (3 strings and 1 button)
i also installed the Nu-GET as instructed
More research for this was required, I found this post which explains how to do it a lot easier and in an application for both 2013/2015, works a treat and can easily be adapted for other screens
https://blogs.msdn.microsoft.com/rmattsampson/2013/03/14/asp-net-signalr-and-lightswitch-vs-2012-update-2-vs-2013-and-later/
I have also managed to edit there block of code to list all messages in a string, this is not stored and refresh's each time but its now possible to have a conversation while on the same screen
var string;
myapp.ChatScreen.created = function (screen) {
string = "";
$(function () {
chat = $.connection.chatHub;
chat.client.broadcastMessage = function (message) {
string = string + message + ";";
screen.updates = string.split(';').join("\r\n");
console.log(string.split(';').join("\r\n"))
};
$.connection.hub.start()
.done(function () {
})
.fail(function () {
alert("Could not Connect! - ensure EnableCrossDomain = true");
});
});
};
It would be better practice using an array and displaying it this way but the code above demonstrates it works

Qt Installer Framework Change Installation path and add subfolder

How to change the installer path and add subfolder using qt installer framework.
Default output:
C:\Program Files (x86)\Subfolder
I want to path to example output.
Example output:
D:\Subfolder
C:\Desktop\Subfolder
C:\Documents\Subfolder
I know this is old but maybe is usefull for someone.
I changed a Qt Installer Framework example called dynamicpage (look in QtIfw examples dir), where the target directory is selected from a custom widget called targetwidgetui. To avoid the user write directly in the line edit I added in my file config/controllerscript.qs this code:
Controller.prototype.TargetDirectoryPageCallback = function()
{
currentPage.TargetDirectoryLineEdit.enabled = false;
}
I also added #ApplicationsDir#/MyAppFolder in config.xml so this is the default install path.
When the user change the destination folder I take the path and append "/MyAppFolder". To do this I changed a function in the dynamicpage example, in file installscript.qs. This is how my function look like now:
Component.prototype.chooseTarget = function () {
var widget = gui.pageWidgetByObjectName("DynamicTargetWidget");
if (widget != null) {
var newTarget = QFileDialog.getExistingDirectory("Choose your target directory.", widget
.targetDirectory.text);
if (newTarget != "")
{
newTarget += "/MyAppFolder"; // The same subfolder of TargetDir in config.xml
widget.targetDirectory.text = Dir.toNativeSparator(newTarget);
}
}
}
Using this you will append always your folder to the installation path.
In your config.xml file you can add
<TargetDir>*YOUR_PATH*/subfolder</TargetDir>
To install to a custom directory.
From Qt Installer Framework documentation:
TargetDir
Default target directory for installation. On Linux, this is usually the user's home directory.
Note that you can use predefined variables like #ApplicationsDir# or #DesktopDir# as stated here.

How to close already open browser from application in Qt

I am using QDeskTopServices to open a URL in my application in Qt, but if the browser is already open in background, it does not come to the foreground and does nothing on calling on QDeskTopServices.
Is there any way to check and close the browser if it is already open in background?
I found an answer for bringing browser to front but still work needed to pass the Url to browser.
#if defined(Q_WS_S60)
TPtrC16 textPtr(reinterpret_cast<const TUint16*>(theUrl.utf16()));
HBufC *param = HBufC::NewMaxLC(textPtr.Length());
param->Des().Copy(_L("4 http://google.com"));
RApaLsSession apaLsSession;
const TUid KBrowserUid = {0x10008D39};
TApaTaskList taskList(CEikonEnv::Static()->WsSession());
TApaTask task = taskList.FindApp(KBrowserUid);
if (task.Exists()){
// Switch to existing browser instance
task.BringToForeground();
HBufC8* param8 = HBufC8::NewLC(param->Length());
param8->Des().Append(*param);
task.SendMessage(TUid::Uid(0), *param8); // UID not used
CleanupStack::PopAndDestroy(param8);
}
else {
if(!apaLsSession.Handle()) {
User::LeaveIfError(apaLsSession.Connect());
}
TThreadId thread;
User::LeaveIfError(apaLsSession.StartDocument(*param, KBrowserUid, thread));
apaLsSession.Close();
}
CleanupStack::PopAndDestroy(param);
#else
//QDesktopServices::openUrl(QUrl("http://google.com"));
#endif
If any suggestion then please add it to the answer.
Problem solved, just add "symbian:TARGET.CAPABILITY += SwEvent" in your project.pro file and make signed app. This will solve the problem :)
QDesktopServices::openUrl(QUrl("http://google.com"));
using the above line you can open browser. And also just add "symbian:TARGET.CAPABILITY += SwEvent" in your project.pro file and make signed app.
Refer this LINK

openWithDefaultApplication fails on files in application folder

I'll ONLY recieve an "Error #3000: Illegal path name" if I try to open a file which is placed inside the app-folder of the air. If the file is somewhere else outside of the app-folder it works.
private var file:File = File.documentsDirectory;
public function download():void{
var pdfFilter:FileFilter = new FileFilter("PDF Files", "*.pdf");
file.browseForOpen("Open", [pdfFilter]);
file.addEventListener(Event.SELECT, fileSelected);
}
private function fileSelected(e:Event):void
{
var destination:File = File.applicationDirectory
destination = destination.resolvePath("test.pdf");
/*
//This works, also if the file to copy is placed inside the appfolder
file.copyTo(destination, true);
*/
/*This Throws me an Error #3000, but ONLY if the file is located in
the App folder*/
file.openWithDefaultApplication();
}
When i try to get the same file and copy it to another place it's doing fine.
Why that? Something special to do if i wanna open files which are inside the appfolder?
It also don't work in debug mode - bin-debug.
Regards, Temo
After reading the document a few times i saw that this is not possible (it's not a bug, it's a feature!?!)
Opening files with the default system application
You cannot use the openWithDefaultApplication() method with files located in the application directory.
So I do this instead:
file.copyTo(tempFile);
tempFile.openWithDefaultApplication();
Not so nice, but it works.

Find workspace location using ANT

I'm working on a build script in the Flash Builder version of Eclipse. This build script needs to import launch configuration .launch files into the user's workspace. However there doesn't seem to be an available ANT var for determining the workspace location. While stepping through the available vars with intellisense I noticed that ${osgi.instance.area} does point to my current workspace but when I tried to echo it back in a running ant script it just spat out "${osgi.instance.area}" and not the path.
Any help would be greatly appreciated. Thank you!!!
If anyone is curious here is how I achieved this, however this is specifically tailored to Flash Builder/Flex Builder (as that's what our team uses) and unfortunately I could never get the ${eclipse.home} property to work in Ant so I had to use ${eclipse.pdebuild.scripts} to get at the installation directory:
<property name="install_loc" value=""/>
<!-- find the eclipse install location -->
<script language="javascript">
<![CDATA[
// Because ${eclipse.home} is not available, determine the install
// location using the pdebuild.scripts location
self.log("Looking for Eclipse installation...");
var base = project.getProperty("eclipse.pdebuild.scripts");
var path_pieces = base.split("/");
var path = "";
outterLoop: for(var i = path_pieces.length; i >= 0; --i)
{
if(path_pieces[i] == "Adobe Flash Builder 4" || path_pieces[i] == "Adobe Flex Builder 3")
{
// After determining which array item refers to the Adobe Flash Builder or Flex Builder
// installation, start at the beginning of the array and count up to that point, adding
// paths as you go.
var k = 0;
while( k <= i )
{
path += path_pieces[k] + "/";
++k;
}
break outterLoop;
}
}
// TODO: MAKE SURE THE PATH IS NOT EMPTY
self.log("Install path found at: " + path);
project.setProperty("install_loc", path);
]]>
</script>
<loadfile
property="workspace_prefs"
srcFile="${install_loc}configuration/.settings/org.eclipse.ui.ide.prefs">
</loadfile>
<property name="workspace_loc" value=""/>
<scriptdef name="find-workspace" language="javascript">
<attribute name="workspace_data"/>
<![CDATA[
// Find and return the workspace location
self.log("Looking for Eclipse workspace...");
var defs = attributes.get("workspace_data").split("=");
var loc = defs[defs.length - 1];
self.log("Workspace found: " + loc);
project.setProperty("workspace_loc", loc);
]]>
</scriptdef>
<find-workspace workspace_data="${workspace_prefs}" />
</target>
FWIW, I think this may give you similar functionality to the javascript part of your solution. The regular expression may be too simplistic for real-world use.
<pathconvert property="install_loc" dirsep="/">
<path location="${eclipse.pdebuild.scripts}"/>
<regexpmapper from="(^.*/Adobe [^/]*)" to="\1/"/>
</pathconvert>
For reference: Ant pathconvert and mapper docs.
This worked for me with a regular Eclipse installation, providing the script is run in Eclipse's own JVM:
<eclipse.convertPath resourcepath="workspace_loc:/" property="eclipse.workspace.home"/>
In order to denote an Ant script should run in Eclipse's own JVM, open the "External Tools Configurations..." dialog, choose your script from the left panel, go to the "JRE" tab, and choose the obvious radio button.
Amnon Grossman

Resources