Unpack a rar file - vb.net

Okay, so I have searched for dll files that will allow me to unrar files and I was able to find quite a few such as unrar.dll, chilkat, sharpcompress and some more but I wanted to use the one provided by Rar themselves.
So I referenced the DLL file in my project and imported it. I was using unrar.dll.
But I wasn't able to find any up to date code to allow me to test and try things out. All the examples I found were either not up to date or not for Vb.net.
I also tried the official example, which came in the installation but that didn't work even after I fixed it and when I tried to use the code I always got an error for
object reference not set to an instance of an object
I just want to unrar a rar file from a specific location to the root directory of my program so if my program was on the desktop I want it to unrar a file in My documents and extract the files to my desktop.

If you just want to unrar files, I Was able to do that with SharpCompress
First I created a new VB.Net App and added a reference to SharpCompress.dll before using this code to extract all the files from a Rar file.
'Imports
Imports SharpCompress.Archives
Imports SharpCompress.Common
'Unrar code
Dim archive As IArchive = ArchiveFactory.Open("C:\file.rar")
For Each entry In archive.Entries
If Not entry.IsDirectory Then
Console.WriteLine(entry.Key)
entry.WriteToDirectory("C:\unrar", New ExtractionOptions With
{.ExtractFullPath = True, .Overwrite = True})
End If
Next
More code samples

for those who will try in vb.net the extract options are renamed and used as
Dim options As New ExtractionOptions With {
.ExtractFullPath = True,
.Overwrite = True
}
entry.WriteToDirectory(Application.StartupPath, options)

Related

How to find the path to the executable of a program

In a VB.NET application I need to set a button to start a program - specifically, Steam. But I need to allow for the user having installed the program somewhere other than the default location "C:\Program Files (x86)\Steam". So all I know is the executable name: "steam.exe".
In searching for an answer it looks like I should be able to get the path using Microsoft.Win32.Registry somehow, but the examples I'm seeing aren't helping me (I guess I'm just not getting how to apply those examples to my situation).
This tutorial gives the example of finding the path to the excel executable:
Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\MICROSOFT\Windows\CurrentVersion\AppPaths\excel.exe")
Dim path As String = regKey.GetValue("Path").ToString
But I'm getting a value of "Nothing" for regKey. Not only that, even if it did get a value for regKey, how would I know the registry path for another program (Steam, in my case)?
And how much will the version of Windows change the possible registry location of a program - if at all?

Error converting Java.io.File to org.core.resource.IFile?

I am dynamically creating a File in the workspace and trying to generate a IFile instance of it.
IPath location= Path.fromOSString(file.getAbsolutePath());
IFile iFile=ResourcesPlugin.getWorkspace().getRoot().getFile(location);
FileEditorInput input = new FileEditorInput(iFile);
but when I try to see if ifile exists or not (using iFile.exists()) it gives false.
I tried using canonical path as well but that also did not help.
Changes to the file system are not automatically detected by the Eclipse workspace, you'll need to tell the workspace to refresh its view of the local file system. You can do this with:
iFile.refreshLocal(IResource.DEPTH_ZERO, null);
If more than one file has changed you can do the refresh at the folder level changing the depth.

Opening an excel file in vb.net

Is there a way to just call Open() function with the file name and extension (xlApp.Workbooks.Open(“Test.xlsx”)) and have it search your whole computer for the file? I know you can open the file if it has a specified path like "c:\docume~1(username)\desktop\Test.xlsx" but I was wondering if there's a way to search your whole computer for the file without specifying the whole path.
You could use:
string[] fileNames = Directory.GetFiles("C:\\", "yourFile.xls",
SearchOption.AllDirectories);
or
var txtFiles = Directory.EnumerateFiles("C:\\", "yourFiles.xls",
SearchOption.AllDirectories);
but you should read carefully the documentation (GetFiles) (EnumerateFiles) on MSDN because there are numerous facts to be prepared of. (Unauthorized Access Exceptions, Search times)

an error 3013 thrown when writing a file Adobe AIR

I'm trying to write/create a JSON file from a AIR app, I'm trying not so show a 'Save as' dialogue box.
Here's the code I'm using:
var fileDetails:Object = CreativeMakerJSX.getFileDetails();
var fileName:String = String(fileDetails.data.filename);
var path:String = String(fileDetails.data.path);
var f:File = File.userDirectory.resolvePath( path );
var stream:FileStream = new FileStream();
stream.open(f, FileMode.WRITE );
stream.writeUTFBytes( jsonToExport );
stream.close();
The problem I'm having is that I get a 'Error 3013. File or directory in use'. The directory/path is gathered from a Creative Suite Extension I'm building, this path is the same as the FLA being developed in CS that the Extension is being used with.
So I'm not sure if the problem is that there are already files in the directory I'm writing the JSON file to?
Do I need to add a timer in order to close the stream after a slight delay, giving some time to writing the file?
Can you set up some trace() commands? I would need to know what the values of the String variables are, and the f.url.
Can you read from the file that you are trying to write to, or does nothing work?
Where is CreativeMakerJSX.getFileDetails() coming from? Is it giving you data about a file that is in use?
And from Googling around, this seems like it may be a bug. Try setting up a listener for when you are finished, if you have had the file open previously.
I re-wrote how the file was written, no longer running into this issue.

I can't get netbeans to find a txt file I have in the same directory... java.io.FileNotFoundException

I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile around in a few different folders (the src folder, and other random folders in the project's NetBeansProjects folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
Try adding the file to build path ..
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:\MyFiles\Athletics.txt');
hope this helps clear the problem up :)