use beanshell to execute a scripts from a specific folder (error no such file or directory) - beanshell

I added the library bsh to my android project (jar file), the I create a file executor.bsh under scripts(a folder that I have created under the project)
I used the code below
private final Interpreter i= new Interpreter();
i.source("scripts/executor.bsh");
I got an error:
No such file or directory
Help !!

Interpreter.source(..) looks for a File, where you have a jar entry. However, you can still use it with:
try (Reader script = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("scripts/executor.bsh")) {
Interpreter in = new Interpreter(script, System.in, System.out, System.err, false);
// your script was already loaded
// do something with Interpreter here.
}

Related

How do I generate a file based on user input in MSI created using WixSharp?

I created an installation MSI package using WixSharp. I have a custom dialog with language, server, etc. options. I want to generate an application config file based on these options and deploy it next to the .exe file as part of an installation process. If it is possible, how should I do that?
You can subscribe on AfterInstall event (when files has been coppied) and modify your config file there.
AfterInstall demostration
project.AfterInstall += project_AfterInstall;
...
static void project_AfterInstall(SetupEventArgs e)
Installation directory you can find here:
private void OnAfterInstall(SetupEventArgs e)
{
var installationPath = e.Session["INSTALLDIR"];
// Change your config file here
// if you need to modify your file once time after installation
// just add this one condition if (e.IsInstalled) { ... }
}

how to download exe files in vb.net (Visual Studio 2015)

I try make one program for download one .exe file and run for help in my job.
But idk how to make this, i'm new in VB.
I am using this code, as shown in the Visual Basic document reference:
My.Computer.Network.DownloadFile _
("http://www.cohowinery.com/downloads/WineList.txt", _
"C:\Documents and Settings\All Users\Documents\WineList.txt")
But when I try to download an .exe file, the entire file doesn't complete and I the file is only 1 kb after download.
The webclient should be the way to go a comment above highlights that too.
This is an example from another question:
Either use sync method:
public void DownloadFile()
{
using(var client = new WebClient())
{
client.DownloadFile(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
}
}
Or use new async-await approach:
public async Task DownloadFileAsync()
{
using(var client = new WebClient())
{
await client.DownloadFileTaskAsync(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
}
}
Then call this method like this:
await DownloadFileAsync();
Open up the .exe file you are trying to download in a text editor like NotePad. Odds are what is being downloaded is an HTML page showing some kind of error message like 404 not found.
Another possibility might be that AntiVirus software is moving the original EXE into quarantine and replacing it with a Quarantine MetaData file.
If the file does actually contain binary content your connection could be getting interrupted but odds are if this happened an exception would be thrown.

writing files in exported eclipse rcp product

I am a newbie and I am working on eclipse-rcp and trying to build a address book with data saved in xml files.when I am running the project it is able to read and write into the xml file but when I am exporting it into a rcp product it is only reading the file but not able to write.
I tried searching Google but couldn't find the relevant answers so I turned to SO.
Any suggestions??
Edit This is my method where I am trying to read the file and writing it into xml file
public void writedata() {
try {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
URL fileURL = bundle.getEntry("/xmlfiles/person.xml");
InputStream inputStream=fileURL.openStream();
Document xmlDocument = builder.parse(inputStream);
..................................................
..................................................
..................................................
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(xmlDocument);
Bundle bundle1 = Platform.getBundle(Activator.PLUGIN_ID);
URL fileURL1 = bundle1.getEntry("/xmlfiles/person.xml");
StreamResult result = new StreamResult(new File(FileLocator.resolve(fileURL1).getPath()));
transformer.transform(source, result);
When you run your application from Eclipse it uses the expanded project folder for your plugin. Your XML file is writeable in this location.
When you export as an RCP application your plugin gets packaged up as a plugin jar file with the XML file inside it. You won't be able to write to this file.
For the file to be writeable it needs to be outside your plugin project, either in the RCP application workspace or in an external folder.

Launching .vsto file after installation. (InstallShield)

I have an msi installer, made via InstallShield, which moves some files to required location,
writes some info to registry and installes VSTO runtime. But I need to launch the .vsto file, that is installed with the application, after the installation is over. Can I do this with custom actions? If that file was an .exe file, that would be rather easy, but how could I launch a .vsto file?
[upd]
Well, may be there is an easier solution:
Can I just call the function:
public override void Install(IDictionary stateSaver)
from InstallShield? Something like that:
Custom Action->Call a function in a Windows Installer dynamic link library->stored in binary table=>
AssemblyFile = \InclusionListCustomActions.dll
MethodSignature = InclusionListCustomActions.TrustInstaller.Install(but what parameter goes here?)
You shouldn't launch the VSTO file because this will only install it per-user. What you should do is add it to the AddIns registry key for the office application you need and use the |vstolocal attribute to tell it to not deploy to the click once cache.
you can follow steps described in http://msdn.microsoft.com/en-us/library/cc563937%28v=office.12%29.aspx, you can copy same steps in Installshield, After file is copied and registry value set as specified, on starting office app it will automatically pick up vsto file
To add information to inclusion list you will have to write a console application and then call console app from installshield. Below code will help
string RSA_PublicKey = #"<RSAKeyValue><Modulus></Modulus></RSAKeyValue>";
//get this key from .vsto file
try
{
SecurityPermission permission =
new SecurityPermission(PermissionState.Unrestricted);
permission.Demand();
}
catch (SecurityException)
{
Console.WriteLine(
"You have insufficient privileges to " +
"register a trust relationship. Start Excel " +
"and confirm the trust dialog to run the addin.");
Console.ReadLine();
}
Uri deploymentManifestLocation = null;
var excelPath = YourAPPPath;
if (Uri.TryCreate(excelPath,
UriKind.RelativeOrAbsolute, out deploymentManifestLocation) == false)
{
Console.WriteLine(
"The location of the deployment manifest is missing or invalid.");
Console.ReadLine();
}
if (!File.Exists(excelPath))
{
UserInclusionList.Remove(deploymentManifestLocation);
Console.WriteLine(deploymentManifestLocation.ToString() + "removed from inclusion list");
}
else
{
AddInSecurityEntry entry = new AddInSecurityEntry(
deploymentManifestLocation, RSA_PublicKey);
UserInclusionList.Add(entry);
Console.WriteLine(deploymentManifestLocation.ToString() + "Added to inclusion list");
}

Troubleshooting "System property mbrola.base is undefined. Will not use MBROLA voices" when converting text to speech with JSAPI

I'm getting the following error:
System property "mbrola.base" is undefined. Will not use MBROLA voices.
import javax.speech.*;
import javax.speech.synthesis.*;
import java.util.Locale;
public class HelloWorld
{
public static void main(String args[])
{
try
{
// Create a synthesizer for English
Synthesizer synth = Central.createSynthesizer(
new SynthesizerModeDesc(Locale.ENGLISH));
// Get it ready to speak
synth.allocate();
synth.resume();
// Speak the “Hello world” string
synth.speakPlainText("Hello", null);
// Wait till speaking is done
synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
// Clean up
synth.deallocate();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
For those who are still struggling with this one, here's how I got it to work on Windows in a plain notepad, no Eclipse involved.
I went to http://tcts.fpms.ac.be/synthesis/mbrola.html
and downloaded 2 packages under downloads of binary voices:
PC/Windows and PC/DOS
unzip it all and put PC/Windows binary in the same directory as PC/DOS executable mbrola.exe.
Please note mbrola.exe didn't work for me b/c it's 16-bit (go figure!), but i found this link:
http://sourceforge.net/projects/freetts/forums/forum/137669/topic/1219083
which had a zip file with 2 binaries, one from 2004 that appeared to work on my 64-bit Windows.
Then I downloaded the voices on mbrola website up above in section 1 I
wanted a female voice so I grabbed us1 and put the whole folder into the same directory as
PC/Windows binaries above and PC/DOS executable.
In the code i specified the following:
System.setProperty("mbrola.base", "C:\devsrc\main\Head-Rev\src\java\freetts-1.2\mbrola");
voice=vm.getVoice("mbrola_us1");
And I got my female voice. I didn't need any compile or runtime flags.
Hope this helps someone.
For me :
I downloaded Mbrola Tool
I downloaded Mbrola Base folder
Downloaded the required voice from Getting the MBROLA Voices section of Mbrola Site
Unziped the file from step 3 to the unziped directory got from step2 .
Set property "mbrola.base" by using : System.setProperty("mbrola.base", "E:\\xxx\\xxx\\mbrxxx");
Your code needs MBROLA app which is in the system. So you need to tell your application that MBROLA is here:
From command line or eclipse launch configuration: -Dmbrola.base=/location/to/mbrola OR
System.setProperty("mbrola.base", Morbola.class.getName()) and put the mbrola JAR is the classpath.
See this similar question
(You can use any one of the solution)
Works on Windows Systems for setting the mbrola.base:
- set environment variable "MBROLA_HOME" in the windows os
- use this code snippet to set the property mbrola.base
public class FreeTTSVoice {
private static String path = System.getenv("MBROLA_HOME");
// System.out.println(path);
public FreeTTSVoice(){
System.setProperty("mbrola.base", path);
listAllVoices();
}
public static void listAllVoices() {
System.out.println("All voices available:");
VoiceManager voiceManager = VoiceManager.getInstance();
Voice[] voices = voiceManager.getVoices();
for (int i = 0; i < voices.length; i++) {
System.out.println(" " + voices[i].getName()
+ " (" + voices[i].getDomain() + " domain)");
}
}
...
Because I used maven repository for mbrola instead of downloading it, I had to override this file in my java project: com.sun.speech.freetts -> internal_voices.txt and to add there:
# Uncomment to allow MBROLA voices:
de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory
I am using ubuntu
If you are using windows you will required only step 1 and 2 .
Created a folder called mbrola
1. put downloaded mbrola-base for my operating system linux to it
2. put downloaded us1, us2, us3 extracted folders to this folder
3. Install the mbrola in ubuntu by command line.
sudo apt-get istall mbrola
After installation use this commad to check where your files has located
dpkg -L mbrola
Copied /usr/bin/mbrola file to the above mbrola folder
Update the program with the path to above program
System.setProperty("mbrola.base", "/home/ngs/INCUBATOR/egg-8/libries/MBROLA/mbrola");
Now it should work