I'm working on custom action and wix.The files are not extracting in program files (x86) folder.But the files are extracting correctly other than program files (x86). I have written code using .NET FRAMEWORK 4.0.
namespace Installer
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("Begin Extracting");
string FinalPath = session["APPDIR"];``
string zPath = #"C:\Users\AppData\Local\Temp\Install\7za.exe";
string ExtractPath = #"C:\Program Files (x86)\Samples\";
string sourcePath = #"C:\Program Files (x86)\Samples\source.zip";
try`
{
ProcessStartInfo pro = new ProcessStartInfo();``
pro.WindowStyle = ProcessWindowStyle.Hidden;
pro.FileName = zPath;
pro.Arguments = "x \"" + sourcePath + "\" -o" + ExtractPath;
Process x = Process.Start(pro);
x.WaitForExit();
}
catch (System.Exception Ex)
{
}
return ActionResult.Success;
}
}
}
First of all you need to debug it properly. You're throwing away any error that might be thrown. Sorry to say this, but your question is unfortunately more like "how can I find out why my code is not working when I've thrown away any exceptions it might raise?"
There's no guarantee that the zip extension will work correctly just by starting it. It might work if WinZip is installed, but not if all that happens is that Explorer opens to look at the files.
You should use the classes that will unzip it. Example here:
https://msdn.microsoft.com/en-us/library/ms404280(v=vs.110).aspx
Related
I have an application where I need to show the .pptx and .pdf files. For pdf files I am using react-native-pdf and file is opening fine in my App but when it comes to .pptx files we have 2 libraries:
1. https://www.npmjs.com/package/react-native-doc-viewer
2. https://www.npmjs.com/package/react-native-file-viewer
react-native-doc-viewer is not being actively maintained and a lot of issues :(
But both of them were giving a prompt to select an app like Wps Office or Microsoft apps but they were not opening as Pdf files opened in my app. Whats the reason behind this? We cannot open pptx file in our app?
I read the react-native-doc-viewer android native code. it is actually is to download a doc not to view it. the following is the code:
#ReactMethod
public void openDoc(ReadableArray args, Callback callback) {
final ReadableMap arg_object = args.getMap(0);
try {
if (arg_object.getString("url") != null && arg_object.getString("fileName") != null) {
// parameter parsing
final String url = arg_object.getString("url");
final String fileName =arg_object.getString("fileName");
final String fileType =arg_object.getString("fileType");
final Boolean cache =arg_object.getBoolean("cache");
final byte[] bytesData = new byte[0];
// Begin the Download Task
new FileDownloaderAsyncTask(callback, url, cache, fileName, fileType, bytesData).execute();
}else{
callback.invoke(false);
}
} catch (Exception e) {
callback.invoke(e.getMessage());
}
}
it uses FileDownloaderAsyncTask to download files. if you are familiar with it.
if you want to show excels, Docx, you can use the google doc line convert it to Html, then in the webView to show it. the format like it: https://docs.google.com/gview?embedded=true&url=[doc address], the same effect as ios.
I am importing a library that reads from the file system instead of my web archive's resource folder. I want to be able to essentially mock that file by adding an asset with that path using ShrinkWrap, so I can run tests on my build server without guaranteeing the file system has all these files. I tried to add a String Asset in the appropriate path, but the code can't find that asset. Here's an example of what I'm trying to achieve.
Rest Resource
#Path("/hello-world")
public class HelloWorldResource {
#GET
public Response getHelloWorld(){
return Response.ok(getFileContent()).build();
}
private String getFileContent() {
StringBuilder builder = new StringBuilder();
try {
BufferedReader bufferedReader = new BufferedReader(
new FileReader(
"/usr/myFile.txt"));
String line = bufferedReader.readLine();
while (line != null) {
builder.append(line);
line = bufferedReader.readLine();
}
}
catch (Exception e) {
e.printStackTrace();
}
return builder.toString();
}
}
Test
#RunWith(Arquillian.class)
public class HelloWorldResourceTest {
#Deployment
public static WebArchive createDeployment()
{
WebArchive webArchive = ShrinkWrap
.create(WebArchive.class)
.addPackages(true,
HelloWorldApplication.class.getPackage(),
HelloWorldResource.class.getPackage(),
Hello.class.getPackage())
.add(new StringAsset("Blah"),"/usr/myFile.txt")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
System.out.println("WebArchive: " + webArchive.toString(true));
return webArchive;
}
#Test
#RunAsClient
public void testHello(
#ArquillianResteasyResource("hello-world") final WebTarget webTarget)
{
final Response response = webTarget
.request(MediaType.APPLICATION_JSON)
.get();
String hello = response.readEntity(String.class);
System.err.println("Hello: " + hello);
Assert.assertEquals("Status is not OK", response.getStatus(), 200);
}
}
Web Archive toString
/WEB-INF/
/WEB-INF/classes/
/WEB-INF/classes/com/
/WEB-INF/classes/com/
/WEB-INF/classes/com/
/WEB-INF/classes/com/helloworld/
/WEB-INF/classes/com/helloworld/application/
/WEB-INF/classes/com/helloworld/application/HelloWorldApplication.class
/WEB-INF/classes/com/helloworld/resource/
/WEB-INF/classes/com/helloworld/resource/HelloWorldResourceTest.class
/WEB-INF/classes/com/helloworld/resource/HelloWorldResource.class
/WEB-INF/classes/com/helloworld/dataobjects/
/WEB-INF/classes/com/helloworld/dataobjects/Hello.class
/WEB-INF/beans.xml
/usr/
/usr/myFile.txt
I get the following error:
java.io.FileNotFoundException: /usr/myFile.txt (No such file or
directory)
Seems like ShrinkWrap is adding /usr/myFile.txt as a relative path within the archive instead of making it seem like /usr/myFile.txt is at the root directory of my file system. Is there any way I can get ShrinkWrap to do what I want?
Shrinkwrap is intended to create archives, so the API is scoped to create assets within the archive you are creating. If you want to have resources created in the regular filesystem simply use JDK, there is nothing Shrinkwrap could help you with.
Alternatively, if possible, change your resource to read resources from the classpath, not filesystem path. With this approach, you can easily swap content for the test using Shrinkwrap as you are trying now with your example.
I am trying to create a small GUI that will rename a file (eventually a batch of files). I am using C++ and Windows user (Visual Studio Community 2015).
I have a btnSelectFiles button with which I want to open a file selection GUI.
I am trying to use openFileDialog but am struggling to set the file name to a string variable.
The code I am using:
public:
void btnSelectFiles_Click(Object^ /*sender*/, System::EventArgs^ /*e*/)
{
IO::Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = "c:\\";
openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
if ((myStream = openFileDialog1->OpenFile()) != nullptr)
{
// Insert code to read the stream here.
myStream->Close();
}
}
/*String test = openFileDialog1;*/
}
One of my many tries was to use:
String test = openFileDialog1
I also tried:
String test = openFileDialog1.FileName
But received an expression must have class type error.
Please can someone help me solve this and thus help my understanding on the matter. The book I have picked up does not cover this and I have struggled to find help online.
Since you are using c++/CLI ( rather than C++ ) you must write
String^ test = new String( openFileDialog1.FileName );
I have been trying to find the best way to do this I have thought of extracting the contents of the .jar then moving the files into the directory then putting it back as a jar. Im not sure is the best solution or how I will do it. I have looked at DotNetZip & SharpZipLib but don't know what one to use.
If anyone can give me a link to the code on how to do this it would be appreciated.
For DotNetZip you can find very simple VB.NET examples of both creating a zip archive and extracting a zip archive into a directory here. Just remember to save the compressed file with extension .jar .
For SharpZipLib there are somewhat more comprehensive examples of archive creation and extraction here.
If none of these libraries manage to extract the full JAR archive, you could also consider accessing a more full-fledged compression software such as 7-zip, either starting it as a separate process using Process.Start or using its COM interface to access the relevant methods in the 7za.dll. More information on COM usage can be found here.
I think you are working with Minecraft 1.3.1 no? If you are, there is a file contained in the zip called aux.class, which unfortunately is a reserved filename in windows. I've been trying to automate the process of modding, while manipulating the jar file myself, and have had little success. The only option I have yet to explore is find a way to extract the contents of the jar file to a temporary location, while watching for that exception. When it occurs, rename the file to a temp name, extract and move on. Then while recreating the zip file, give the file the original name in the archive. From my own experience, SharZipLib doesnt do what you need it do nicely, or at least I couldnt figure out how. I suggest using Ionic Zip (Dot Net Zip) instead, and trying the rename route on the offending files. In addition, I also posted a question about this. You can see how far I got at Extract zip entries to another Zip file
Edit - I tested out .net zip more (available from http://dotnetzip.codeplex.com/), and heres what you need. I imagine it will work with any zip file that contains reserved file names. I know its in C#, but hey cant do all the work for ya :P
public static void CopyToZip(string inArchive, string outArchive, string tempPath)
{
ZipFile inZip = null;
ZipFile outZip = null;
try
{
inZip = new ZipFile(inArchive);
outZip = new ZipFile(outArchive);
List<string> tempNames = new List<string>();
List<string> originalNames = new List<string>();
int I = 0;
foreach (ZipEntry entry in inZip)
{
if (!entry.IsDirectory)
{
string tempName = Path.Combine(tempPath, "tmp.tmp");
string oldName = entry.FileName;
byte[] buffer = new byte[4026];
Stream inStream = null;
FileStream stream = null;
try
{
inStream = entry.OpenReader();
stream = new FileStream(tempName, FileMode.Create, FileAccess.ReadWrite);
int size = 0;
while ((size = inStream.Read(buffer, 0, buffer.Length)) > 0)
{
stream.Write(buffer, 0, size);
}
inStream.Close();
stream.Flush();
stream.Close();
inStream = new FileStream(tempName, FileMode.Open, FileAccess.Read);
outZip.AddEntry(oldName, inStream);
outZip.Save();
}
catch (Exception exe)
{
throw exe;
}
finally
{
try { inStream.Close(); }
catch (Exception ignore) { }
try { stream.Close(); }
catch (Exception ignore) { }
}
}
}
}
catch (Exception e)
{
throw e;
}
}
I am using the YUI Compressor library to minify CSS and JavaScript files. I directly use the classes CssCompressor and JavaScriptCompressor.
Unfortunatly some of the resulting files are empty without any warnings or exceptions.
I already tried it with the versions:
yuicompressor-2.4.2.jar
yuicompressor-2.4.6.jar
yuicompressor-2.4.7pre.jar
My used code is:
public static void compress(File file) {
try {
long start = System.currentTimeMillis();
File targetFile = new File("results", file.getName() + ".min");
Writer writer = new FileWriter(targetFile);
if (file.getName().endsWith(".css")) {
CssCompressor cssCompressor = new CssCompressor(new FileReader(file));
cssCompressor.compress(writer, -1);
} else if (file.getName().endsWith(".js")) {
JavaScriptCompressor jsCompressor = new JavaScriptCompressor(new FileReader(file), new MyErrorReporter());
jsCompressor.compress(writer, -1, true, false, false, true);
}
long end = System.currentTimeMillis();
System.out.println("\t compressed " + file.getName() + " within " + (end - start) + " milliseconds");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Files which do not work (are empty afterwards) are e.g.
http://code.google.com/p/open-cooliris/source/browse/trunk/fancy/jquery.fancybox.css?r=2
http://nodejs.org/sh_main.js
I know there are some bugs within the YUICompressor using media but could this be in relation with the empty results?
I had the same problem.
In my case it stemmed from that my javascript code was not ECMA valid (we use a variable named double which is not allowed according to the ECMA rules).
I did not have the courage to check if your js is valid but trying to compress different parts of your js file can easily lead you to the problem if it exists.
Well, after a while of debugging I figured out a solution.
The problem was not the YUI Compressor it self but it was the FileWriter given to the method.
Flushing an closing the FileWriter should solve the problem with empty result files
since I only need the minified String for further processing I now use a StringWriter with closing and flushing