Receiving the path of a VS2010 extension? - visual-studio-2010

I've written a small Extension for VS2010 (vsix file), within the vsix is a binary file, which gets called by the extension.
I try to open the file like this:
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = #".\Binaries\TFPT.exe"}
Which works fine if I debug everything. But if I install it, I get a "file not found" error. The Binaries are installed correctly.
So I thought I try to get the complete path to the binaries. But how can I get the path? All Application.Path infos are not pointing to the correct path. Is there a way to get the path of the extension directory?
The path is something like:
C:\Users[username.domain]\AppData\Local\Microsoft\VisualStudio\10.0\Extensions[Company][ExtensionName]\1.0
Any idea without putting it together by hand?

How about retrieving the path from the current executing assembly and use Path.Combine() with your the remaining relative path segment ?
Note: This piece of code comes from a SO answer.
private static string RetrieveAssemblyDirectory()
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}

You can get this path asking for your extension installation path to Visual Studio:
var serviceProvider = [YourPackageObject] as IServiceProvider;
var manager = serviceProvider.GetService(typeof(SVsExtensionManager)) as IVsExtensionManager;
foreach (IInstalledExtension extension in manager.GetInstalledExtensions())
if(extension.Header.Name == [MyExtensionName])
return extension.InstallPath;

Related

Xamarin Windows cannot access the specified device, path, or file

I have a Xamarin application running on Windows, and I have a method which includes an opening of a pdf file like this:
var psi = new ProcessStartInfo
{
FileName = "cmd",
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
CreateNoWindow = true,
Arguments = $"/c start {filename}"
};
Process.Start(psi);
When this executes, the windows opens a dialog with the following message:
Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.
The filename is a pdf file located in the LocalApplicationData, and I also have a database there, and the application is normally creating a database there and manipulates with it, so it should have a permission to access that folder. Also, when I run that pdf with double-click outside the application, the pdf opens normally with Chrome. How to solve this?
Unless you have a file there called "cmd" this won't work, as you have declared your filename as a string with the value "cmd".

To check whether a file has been downloaded or not via protractor

Need help to check whether a file has been successfully downloaded or not in a specified folder.
The file name dynamically changes every time a new file is downloaded but the initial part of the file "Pivot_Report" always stays the same
The actual file gets downloaded in the mentioned folder but protractor is not able to find it with just the initial part of the full name
This is the code I'm using (filenamePath is '/Users/Shubh/Documents/')
browser.driver.wait(function() {
        var fileName = filenamePath+"*.csv"
        var filesArray = glob.sync(fileName)
        if (typeof filesArray !== 'undefined' && filesArray.length > 0){
          return filesArray
        }
      }, 10000).then(function(filesArray) {
        var fileWithPath = filesArray[0]
        var temp = fileWithPath.indexOf("Pivot_Report")
        expect(fileWithPath.indexOf("Pivot_Report") >= 0).toBe(true,'Pivot Download is not succesfull')
        if(fs1.existsSync(fileWithPath)){
          fs1.unlinkSync(fileWithPath)
        }
      })
Getting the timeout error
It happens, because your path is incorrect.
I think easiest way is to use path.resolve() :
var path = require("path");
var filenamePath = path.resolve("Users/Shubh/Documents");
and then you will have (notice that you missed a / before *.csv)
var fileName = filenamePath+"/*.csv"

Relative directory paths in Visual Studio using FSharp

I have a file located in a solution directory like this:
I want to read the contents of one of the .txt files into a string in the FSI:
open System.IO
[<Literal>]
let path = "../Data/Build_Keynote2014.txt"
let buildKeynote = File.ReadAllText(path)
The problem is that it is throwing an exception:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\jamie\AppData\Local\Data\Build_Keynote2014.txt'.
Is there a way to reference the file without using the full path?
Thanks
After some research, I found this post
let baseDirectory = __SOURCE_DIRECTORY__
let baseDirectory' = Directory.GetParent(baseDirectory)
let filePath = "Data\Build_Keynote2014.txt"
let fullPath = Path.Combine(baseDirectory'.FullName, filePath)
let buildKeynote = File.ReadAllText(fullPath)
works like a charm. Thanks everyone who submitted.

How to stop xcode debugger from mangling filesystem NSURLs on OS X?

I am trying to write a Mac app that converts files. I am stuck at the beginning because my app cannot open local files, at least while running in the debugger. I use the NSOpenPanel to create a valid file NSURL:
“file:///Volumes/Seagate_1tib/projects/dataskunk/wasteproduct.xml”
But somewhere in xcode, or the debugger or whatever, this gets mangled into
"/Users/charlweed/Library/Developer/Xcode/DerivedData/dataskunk-ghkiumvdkopxarhavynetidlqxio/Build/Products/Debug/file:/Volumes/bigdrive/dataskunk/wasteproduct.xml"
Reading the file then fails with a "No such file or directory error".
How do I prevent this mangling during development?
For example, this gives the error, no matter what file is chosen:
let fileResult = openFileDialog("Choose File", message:"Message")
let xmlInFileURLOpt: NSURL? = NSURL.fileURLWithPath(fileResult)
if let xmlInFileURL = xmlInFileURLOpt
{
var xmlFileError: NSError?
if !xmlInFileURL.checkPromisedItemIsReachableAndReturnError(&xmlFileError){
println("\(xmlFileError)")
return
}
}
The answer is that NSURL.fileURLWithPath() does not take a URL-path as an argument, only a filesystem-path. So "file:///Volumes/disk/file.xml" is wrong, "/Volumes/disk/file.xml" is correct.
The mangling is NSURL prefixing the current directory onto what it thinks is a relative filesystem-path String.

copy from main bundle to application support swift

I have copied files like this from an application before and have copied the code exactly as it appears in another app but for what ever reason when it try to run this particular code it will only create the new directory.
It will not however save the binary file I have saved in supporting files in the main bundle to the new directory. I have done a fair amount of googling and searching stack overflow and have decided I might have to post something here.
let path = NSBundle.mainBundle().resourcePath?.stringByAppendingPathComponent("youtube-dl")
let destination = "~/Library/Application Support/Youtube DLX/"
let destinationPath = destination.stringByStandardizingPath
NSFileManager.defaultManager().createDirectoryAtPath(destinationPath, withIntermediateDirectories: true, attributes: nil, error: nil)
NSFileManager.defaultManager().copyItemAtPath(path!, toPath: destinationPath + "youtube-dl", error: nil)
note that the file that I am trying to copy has no extension so the full name is just "youtube-dl"
The result of
let destinationPath = destination.stringByStandardizingPath
has no trailing slash, so you are trying to copy the file to
"~/Library/Application Support/Youtube DLXyoutube-dl"
You should use
destinationPath.stringByAppendingPathComponent("youtube-dl")
to generate the target path as you already did for the source path.
Generally (as just mentioned in a comment), you should use the error parameter and
check the return value for success, for example
var error : NSError?
if !NSFileManager.defaultManager().copyItemAtPath(..., error: &error) {
println("copy failed: \(error)")
}

Resources