Absolute file path from selected node in treeview C# - c#-4.0

I am making a GUI file mover using Treeview, the only issue I am having is getting the absolute file path.
When I use this code:
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo sourceDir = new DirectoryInfo(textBox1.Text);
sourceDir.EnumerateFiles();
var fileToMovePath = Path.GetFullPath(treeView1.SelectedNode.FullPath);
var pathToMoveToo = textBox2.Text;
//File.Move(fileToMovePath, pathToMoveToo);
MessageBox.Show(fileToMovePath);
}
I get this file path:
Which obviously isn't what I want, as that file is actually stored on my desktop. Any ideas?

I was facing a similar problem and after some trial and error following solution worked for me.
Replace
var fileToMovePath = path.GetFullPath(treeView1.SelectedNode.FullPath);
With
var fileToMovePath = textBox1.Text + "\\" + treeView1.SelectedNode.Text;
I think the problem here was with path.GetFullPath(), that it was displaying the path to directory from where program is being executed and not the one we picked.

Related

Multiple .zip files extracting on the app directory c#

I have an auto update program for game launcher and I want to know how I can auto unzip all zip files on the same folder with launcher. (Multiple zip files are downloaded). I am a newbie when it comes to coding.
I need to change the following code for extracting all .zip files in the current folder where the app is.
using (var zip = Ionic.Zip.ZipFile.Read("desktop.zip"))
{
zip.ExtractAll(Directory.GetCurrentDirectory(), ExtractExistingFileAction.OverwriteSilently);
}
Try using Reflection:
using (var zip = Ionic.Zip.ZipFile.Read("desktop.zip"))
{
string exeFullPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string exePath = System.IO.Path.GetDirectoryName(exeFullPath);
zip.ExtractAll(exePath
, ExtractExistingFileAction.OverwriteSilently);
}
#vendettamit is give me the correct answer. If someone need im going to post his code.
foreach (var file in Directory.EnumerateFiles("<directory path>", "*.zip"))
{
using (ZipFile zip = ZipFile.Read(file))
{
foreach (ZipEntry zipFiles in zip)
{
zipFiles.Extract(currentpath, true);
}
}
}

Ordner nicht angegeben with OmniPascal in VSCode

People get the error when opening a file in Visual Studio Code when using OmniPascal:
Ordner nicht angegeben
which translates to:
Folder not specified
The first thought to ensure the paths in user settings.json are set:
objectpascal.delphiInstallationPath
objectpascal.objectpascal.searchPath
Would of course be a wrong tree to bark up:
settings.json:
// Place your settings in this file to overwrite the default settings
{
"objectpascal.delphiInstallationPath": "D:\\Programs\\Embarcadero\\Studio\\14.0",
"objectpascal.searchPath": "D:\\Delphi Components"
}
The error is definitely coming from OmniPascal, as it is a string inside
bin\win\OmniPascalServer.exe
I'm not the only person to get this
Anonymous has the same issue:
When I open a .pas file by right clicking on the file in windows explorer, the file opens correctly, but then a messagedialog appears with "Ordner nicht angegeben"' and an OK button.
Is there a way to debug Code?
I can see inside VSCode there is a variable to the workspace root path:
objectPascalServiceClient.js
var config = vscode.workspace.getConfiguration('objectpascal');
var delphiSDK = config.get('delphiInstallationPath', '');
var searchPath = config.get('searchPath', '');
var workspacePath = vscode.workspace.rootPath;
if (typeof delphiSDK == 'undefined')
delphiSDK = "";
if (typeof searchPath == 'undefined')
searchPath = "";
if (isWin) {
childProcess = cp.spawn(path.join(__dirname, 'bin/win/OmniPascalServer.exe'), [workspacePath, delphiSDK, searchPath]);
}
Is there source code?
It looks like OmniPascal is abandonware. Is there source code out there where someone can try to decipher exactly?
The real question is how to get rid of the modal dialog that blocks using the window.
It looks like OmniPascal is abandonware
No it's definetely not abandonware even though there was no new public release within the last months. OmniPascal is still in active development.
The real question is how to get rid of the modal dialog that blocks using the window.
This error message is coming from OmniPascalServer.exe shipped with the OmniPascal plugin for VSCode in (the current) version 0.10.0 released on 2016-04-14.
Workaround for version < 0.11.0
As far as I know this error message only appears when a file is opened in Visual Studio Code instead of a folder. So the simplest workaround is to open the folder which contains the file(s) you want to work with:
By command line: Type code C:\Projects\MyProjectRootFolder
With the Windows Explorer: Perform a right click on the folder (or a white area inside the folder) and select Open with Code. Do not select a .pas file to open VSCode!
From within VSCode: Go to File -> Open Folder...
Or apply the hotfix
Open the file C:\Users\USERNAME\.vscode\extensions\Wosi.omnipascal-0.10.0\objectPascalServiceClient.js
Replace this line
var workspacePath = vscode.workspace.rootPath;
with these lines
var workspacePath = vscode.workspace.rootPath;
if (typeof workspacePath == 'undefined') {
var filePath = vscode.workspace.textDocuments[0].fileName;
workspacePath = path.dirname(filePath);
}
Now the error should no longer appear.

Get path to test resource file with Robolectric 3.0

I almost migrated all tests to Robolectric 3.0. It was huge deal :)
I have last failing test because I can not access test database that I used for migration tests. Next code produces NPE:
String filePath = getClass().getResource( "/test.db" ).toURI().getPath();
Do you know a way how to get absolute path to this file in Robolectric 3.0? I want to avoid hardcoding since I want to have test working on all machines
Maybe will be helpful for someone. My code:
private void copyTestDatabase( String resourceDBName )
throws URISyntaxException, IOException
{
String filePath = RuntimeEnvironment.application.getPackageResourcePath() + "/src/test/res" + resourceDBName;
String destinationPath = RuntimeEnvironment.application.getDatabasePath( "<my-db-name>.db" ).getAbsolutePath();
File to = new File( destinationPath );
to.mkdirs();
to.delete();
Files.copy( new File( filePath ), to );
}
Let me know if you have more elegant solution. Post the answer I will accept it

Coded UI Tests don't run on one machine, but run on another

My co-workers and I are working on a Coded UI project. We both have the same version of the project thanks to TFS, but on his computer all the test cases run, and on mine they don't. They used to run perfectly fine on my machine until one morning they decided to not work. I always keep getting the same error that the UI Test Controls are not found, even though the mappings are correct. Let me remind you that they work perfectly fine on my co-workers machine. We also have the same version of IE (11).
What could be the cause for this?
Thanks for the help in advance.
My co-worker seemed to resolve the situation, but we still don't understand why the previous version of the code worked for everyone but my machine. The problem occurred in our LaunchBrowser method which would use 2 different instantiations of the browser variable. He got rid of the unnecessary one and the playback commands and seemed to have fixed the problem.
Below are two versions of the code, the previous one and the newly written one:
Old:
public static void LaunchBrowser(string url)
{
GlobalVariable.browser = new BrowserWindow();
CloseAllBrowsers();
BrowserWindow.CurrentBrowser = GlobalVariable.BrowserType;
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.Disabled;
GlobalVariable.browser = BrowserWindow.Launch();
System.Uri URI = new System.Uri(url);
GlobalVariable.browser.NavigateToUrl(URI);
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.UIThreadOnly;
GlobalVariable.browser.Maximized = true;
if (BrowserWindow.CurrentBrowser == "Firefox")
{
Mouse.Click(_fireFoxAuthOK);
}
Logging.WriteLog("Browser was navigated to " + url + " in browser: <" + GlobalVariable.BrowserType + ">");
}
New:
public static void LaunchBrowser(string url)
{
CloseAllBrowsers();
BrowserWindow.CurrentBrowser = GlobalVariable.BrowserType;
GlobalVariable.browser = BrowserWindow.Launch(new Uri(url));
GlobalVariable.browser.Maximized = true;
if (BrowserWindow.CurrentBrowser == "Firefox")
{
Mouse.Click(_fireFoxAuthOK);
}
Logging.WriteLog("Browser was navigated to " + url + " in browser: <" + GlobalVariable.BrowserType + ">");
}
I think the problem is in this line :
Playback.PlaybackSettings.WaitForReadyLevel = Microsoft.VisualStudio.TestTools.UITest.Extension.WaitForReadyLevel.UIThreadOnly;
Because the browser's foreground thread is not ready to start the playback. you may try this
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;
or different alternative ways in your pc.
Refer this link Mathew Aniyan's Blog for further information.

AAssetManager_openDir crashing app on start

I'm trying to iterate through all the files contained in the assets folder. To get the working directory I use: AAssetManager_openDir. However simply having this in my code causes a crash on startup - android_main doens't even get a look in. Has anybody had similar problems and/or know how to resolve this?
const char* filename = (const char*)NULL;
const char* dirName = "";
AAssetDir* dir = AAssetManager_openDir(assetManager, dirName);
while((filename = AAssetDir_getNextFileName(dir)) != NULL)
{
//action per file
}
AAssetDir_close(dir);
Well I didn't have any luck getting it to work so I tried a different approach.
I compiled a static library of Minizip and, combined with Zlib, opened the APK file (the path of which found via JNIEnv) and found the filenames nestled within, skipping over entries not contained in the assets folder.
Roundabout way to do it but since AAssetManager_openDir isn't working this seemed like the only option.
Still it would be nice if somebody does find the "correct" solution.
const char* dirName = "";
Is probably what is causing the crash.
Instead try:
while(1)
{
const char* filename = AAssetDir_getNextFileName(dir);
if(!filename)
break;
}

Resources