VarToLocalFile - Forum

Forum Navigation
Climate strike banner
You need to log in to create posts and topics.

VarToLocalFile

12

This does not work:

SetVar [Inputvar] "Hello World!"

VarToLocalFile [Inputvar] "myfile.txt"

FileToVar "myfile.txt" [var2]

AlertBox "" "[var2]" ""

 

In what folder is the local file saved?

 

Also, is SetItem of Local Storage saved to a cookie? In what folder?

 

.

 

 

Hi @fkapnist,

Due to security reasons, WebApps can not write files directly to the local file system.
What they do is asking permission to the user to download a file. The user selects where to download it ("downloads" folder by default).

On the other hand FileToVar command is intended to open a file from a URL.
You can use FileToVar "myfile.txt" [var2] if mytextfile.txt is in the same folder than your WebApp index.html and they are located on a web server.

You can use LocalFileToVar instead but you can not choose the local file to open as it is the user the only one who has permission to do so.

Take a look in the samples folder to the filetovar.neoapp (I know it should be named localfiletovar.neoapp, sorry).

Best regards.

OK. I found it in the download folder.....

I want to create a string action command from the Chrome browser and save it as a temporary text file that VisualNEO Win can read and execute with "Call." This is a more stable method of VisualNEO Win communicating with Chrome than the execCommand using the clipboard. Here is what I have in VisualNEO Web:

SetVar [Inputvar] 'ImageWindow "Image" "-1" "-1" "[PubDir]files\image5.bmp"'
VarToLocalFile [Inputvar] "myCall.txt"

But when VisualNEO WIn finally reads myCall.txt, it looks like this:

ImageWindow "Image" "-1" "-1" "undefinedfilesimage5.bmp"

What characters need to be fixed for it to read correctly?

(Note: This method works just fine if the image is also located in the download folder and "[PubDir]files\" is removed from the text string. But I want the image to be elsewhere.)

 

 

is SetItem of Local Storage saved to a cookie

I don't think it will be easy for the Chrome browser to communicate with VisualNEO Win using cookies. Chrome cookies are all stored in one single database file and a special program is required to see them, but they are encrypted anyway

What they do is asking permission to the user to download a file.

Actually, if the Chrome browser is in "kiosk mode" it does not ask anything. There is no annoying notification. It simply saves to the downloads folder, silently, which is exactly what I want...

@fkapnist:

This command ...

SetVar [Inputvar] 'ImageWindow "Image" "-1" "-1" "[PubDir]files\image5.bmp"'

... is serviced in your Web App (built by VisualNEOWeb).

Note that [PubDir] is NOT a pre-defined (Special) variable in VisualNEOWeb; so it is substituted with undefined before being written to your file.

What characters need to be fixed for it to read correctly?

I assume that you are looking for the value of the folder where your Web App is run from.

1) note that there is no such thing if your Web App is located on some distant server/domain (e.g. http://www.mydomain.com/path/to/myWebApp)

2) if you intend to do this with apps built by VisualNEOWeb that are stored on your personal computer, you can do this ...

BeginJS
$App.myURL = document.location.href;
EndJS
AlertBox "myURL" "[myURL]" ""

... which will populate variable [myURL] with the URL of your Web App (i.e. what you see in your browser's Address Box).

You can then parse this string to extract the equivalent of [PubDir]

Thanks. I solved it by completely removing "[PubDir]files\" from my text string.  Instead, I copied myCall.txt from the downloads folder to the same folder as the image that I want to show. In VisualNEO Win I made a patch to locate the "UserDrive" and its path. Then I copied myCall.txt out of the User path and into [PubDir]files\....

Then...   Call "[PubDir]files\myCallX.txt" runs as an external function !

StrReplace "[ProgramFiles]" "Program Files (x86)" "Users\[UserName]" "[UserDrive]" "CaseSensitive"
.AlertBox "" "[UserDrive]"
FileCopy "[UserDrive]Downloads\myCall.txt" "[PubDir]files\myCallX.txt"
SetVar "[CurrentDir]" "[PubDir]files\"
Delay "1000"
Call "[PubDir]files\myCallX.txt"
Delay "1000"
FileErase "[UserDrive]Downloads\myCall.txt"

This is good way to communicate between  the Chrome browser and VisualNEO Win without upsetting the clipboard.

The text file myCall.txt was created by VisualNEO Web and opened in a Chrome browser rectangle inside VisualNEO Win.

It works well and I will post the proof of concept very soon....

.....................................................................................................................

I made a patch to locate the "UserDrive" and its path in order to find where chrome.exe might be found on various user systems:

. Search Program Files
StrReplace "[ProgramFiles]" "Program Files (x86)" "Program Files" "[ProgramFilesWOW64]" ""
FileExists "[ProgramFilesWOW64]\Google\Chrome\Application\chrome.exe" "[i]"
.AlertBox "Find Chrome" "Is Chrome in Program Files?||[i]"
If "[i]" "=" "True"
SetVar "[ChromePath]" "[ProgramFilesWOW64]Google\Chrome\Application\chrome.exe"
AlertBox "Chrome Path" "Chrome Path set to [ProgramFilesWOW64]Google\Chrome\Application\chrome.exe"
Return
EndIf

. Search Program Files x86
FileExists "[ProgramFiles]\Google\Chrome\Application\chrome.exe" "[i]"
.AlertBox "Find Chrome" "Is Chrome in Program Files x86?||[i]"
If "[i]" "=" "True"
SetVar "[ChromePath]" "[ProgramFiles]Google\Chrome\Application\chrome.exe"
AlertBox "Chrome Path" "Chrome Path set to [ProgramFiles]Google\Chrome\Application\chrome.exe"
Return
EndIf

. Search Vista AppData Local
StrReplace "[ProgramFiles]" "Program Files (x86)" "Users\[UserName]" "[UserDrive]" ""
AlertBox "" "[UserDrive]"
FileExists "[UserDrive]\AppData\Local\Google\Chrome\Application\chrome.exe" "[i]"
.AlertBox "Find Chrome" "Is Chrome in AppData Local?||[i]"
If "[i]" "=" "True"
SetVar "[ChromePath]" "[UserDrive]AppData\Local\Google\Chrome\Application\chrome.exe"
AlertBox "Chrome Path" "Chrome Path set to [UserDrive]AppData\Local\Google\Chrome\Application\chrome.exe"
Return
EndIf

. Chrome Not Found
AlertBox "Find Chrome" "The Chrome browser was not found ! | |Please download and install Chrome"
Return

.....................................................................................

 

 

I am using VisualNEO Web and VisualNEO Win together, to make one Windows application. My VisualNEO Web is not located on some distant server/domain.  It is embedded inside the VisualNEO Win program.

VisualNEO Web uses "iframes" which have certain limitations. A browser object built right into the application has no limitations.  Being able to include a Chrome browser rectangle in the program is very good so that now users can have access to their favorite bookmarks, etc. and Chrome browser extensions can be created to communicate with  VisualNEO Win. (Next is Mozilla Firefox.)

Thank you @fkapnist,
Your work is very much appreciated.

fkapnist:

The text file myCall.txt was created by VisualNEO Web and opened in a Chrome browser rectangle inside VisualNEO Win.

If your Pub is invoking the Web App, why not just pass the the Drive and Path of [PubDir] (or whatever location you want the Web App to use to create the txt file) to the Web App as a parameter ? e.g.

?pubdrive=c&pubfolder=whatever

... and have your Web  App pick these values up using ...

GetURLParameter "pubdrive" [pubdrive]
GetURLParameter "pubfolder" [pubfolder]

 

 

Quote from Gaev on January 11, 2019, 3:44 pm

If your Pub is invoking the Web App, why not just pass the the Drive and Path

Thanks, I will try that. Google generally blocks Chrome from local files. But it allows plain text "Blobs" to be downloaded. Since they can communicate with VisualNEO Win, their text should probably be encrypted and created in a hidden AppData folder. This would probably be the best channel of communication so far between the Chrome browser and VisualNEO Win

@fkapnist:

Google generally blocks Chrome from local files. But it allows plain text "Blobs" to be downloaded. Since they can communicate with VisualNEO Win, their text should probably be encrypted and created in a hidden AppData folder.

Alternately, you could include the Call file (designed with one parameter for each possible variable) in your exe file created with VisualNEOWin ... and then just pass the "variable data associated with each parameter" in the "downloaded text file".

In your .exe file ...

a) FileRead the passed data (one line per parameter) in variables like [param1], [param2] etc.

b) Invoke the previously included Call file using [param1], [param2] etc.

You can further obfuscate the data being passed by having just one Call/Subroutine to handle all requests originating from the Browser object (I am assuming you are using WinExecAction); just make the first line of the file contain an alias of the actual Call file to be used e.g. ...

123456 or "Apple" for data to be processed by Call file "pqr"
69389 or "Pear" for data to be processed by Call file "cdef"
345887432 or "Burger" for data to be processed by Call file "xyz"

... the reverse-aliasing would be protected inside your .exe file.

 

Also, I have not tried it, but could you use the WinSetVar command referenced in the Help file for VisualNEOWeb here ...

https://webhelp.visualneo.com/VisualNEOWinCommunication.html

... to pass variable data to the .exe file ?

Quote from Gaev on January 14, 2019, 9:40 pm

Also, I have not tried it, but could you use the WinSetVar command referenced in the Help file for VisualNEOWeb here ...

WinSetVar interacts with the Internet Explorer (IE) WebBrowser object. I am trying to communicate with the Google Chrome browser in a rectangle.

The Chrome browser does not have the open and save menu. It can only communicate with local apps through "blobs" which it saves ONLY to the user downloads folder. VisualNEO Win can then detect it and receive variables or raw data.

Here is the script you need for Chrome to trigger blobs in your local downloads folder:

https://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/

Features of HTML5 (specifically the “Blob” object, the FileAPI, and the “download” attribute of the “a” tag) allow the Chrome browser to load, edit, and save a text file on your local computer. A local text file can be used to communicate with VisualNEO Win. It works in both Chrome and Fire fox browsers.

A binary large object (Blob) is a collection of raw binary data stored as a single entity. (Blobs were originally "chunks of data" named after a 1958 Steve McQueen movie.) Blobs are typically images, audio or other multimedia objects.

@fkapnist:

Thanks for the link to the scripting to enable downloads from inside a Chrome Browser.

VisualNEO Win can then detect it and receive variables or raw data.

How does your exe (developed with VisualNEOWin) "detect" the presence of a newly downloaded text file from the HTML/Javascript running inside a (embedded) Chrome Browser ?

Quote from Gaev on January 15, 2019, 4:50 pm

@fkapnist:

Thanks for the link to the scripting to enable downloads from inside a Chrome Browser.

VisualNEO Win can then detect it and receive variables or raw data.

How does your exe (developed with VisualNEOWin) "detect" the presence of a newly downloaded text file from the HTML/Javascript running inside a (embedded) Chrome Browser ?

The raw data in my project is named "ChromeBlob.txt" and I have a Timer check for that filename in the Downloads folder.

. This method reads from a temporary file and requires the hpwPlayAction plugin.

StrReplace "[ProgramFiles]" "Program Files (x86)" "Users\[UserName]" "[UserDrive]" "CaseSensitive"
.AlertBox "" "[UserDrive]"
FileExists "[UserDrive]Downloads\ChromeBlob.txt" "[ifoo]"
   If "[ifoo]" "=" "True"
   GotoLine "winfile"
   Else
   Return
   EndIf

:winfile
StrReplace "[ProgramFiles]" "Program Files (x86)" "Users\[UserName]" "[UserDrive]" "CaseSensitive"
.AlertBox "" "[UserDrive]"
FileToVar "[UserDrive]Downloads\ChromeBlob.txt" "[ChromeBlobVar]"
Delay "50"
FileErase "[UserDrive]Downloads\ChromeBlob.txt"
Delay "50"
SetVar "[CurrentDir]" "[PubDir]files\"
hpwPlayAction "[ChromeBlobVar]" "1"

 

 

what happen if what you whant to save is from a phone? I try and it say InvalidStateError

What I realy whant to do, is to make a app that will be use to do an inspection of fire extiguisher. So after to check the elements I will get a var to export to a file, then to get the file in the visual win app.

Can you help my, please.

Is my frist app in visual web.

Regards...

Hi @thibeault911,
Sorry I don't understand very well your needs nor the situation where you get the error.
Regards.

Hi Luishp:

Tengo un par de consultas, trate con la opción varToLocalFile, pero no logro que registre en .txt la información de mi variable. tampoco encuentro donde la escribe , solo aparece en el debbug InvalidStateError.

Muchas gracias por la ayuda, manejo muy bien VisualNeo Win, pero estoy pataleando con Visualneo WEB.

Aprovecho para felicitarte por tus programas.

 

Atte.

Thibeault

12