Use SHGetKnownFolderPath() instead of ApplicationData class to get LocalAppData path - winapi

In an desktop-bridge app, I want to find the LocalAppData (or LocalCache) folder of that specific package. I can get the LocalCache folder path with ApplicationData class:
using Windows.Storage;
string appData = ApplicationData.Current.LocalCacheFolder.Path;
Alternatively, if I use SHGetKnownFolderPath function I can also get that same path:
wchar_t* appData;
SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_FORCE_APP_DATA_REDIRECTION, NULL, &appData);
So my question: Is it appropriate to use SHGetKnownFolderPath() instead of ApplicationData class? Both give same path in UWP environment. Is there any drawback/cons to use the first one?

You could call any methods before you convert your desktop app to UWP app.
Once you converted it successfully, after that, if you want to extend it, for example: Extend your desktop application with modern UWP components, then, you would have to use UWP APIs.

Related

Launcher.LaunchUriAsync does not work on Xamarin Forms UWP [duplicate]

no Error just nothing happen and file target still there in my path
public void keyboard(){
ProcessStartInfo touchkey = new ProcessStartInfo(#"C:\Program
Files\Common Files\microsoft shared\ink\TabTip.exe");
touchkey.WorkingDirectory = #"C:\";
touchkey.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(touchkey);
}
Update
The suggested solution threw a `UnauthorizedAccessException`:
var path = #"ms-appx://C:/Program Files/Common Files/microsoft
shared/ink/TabTip.exe";
var file = await
Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(path);
await Windows.System.Launcher.LaunchFileAsync(file);
Update2
I try to use FullTrustProcessLauncher it's work fine but like code before Keyboard tabtip.exe not show I dont know what should I do
await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
});
UWP applications are sandboxed and cannot launch other processes directly due to security restrictions.
The only way to launch other applications is if those applications have a URI registered, or an application is a default handler for a particular file type.
In those instances, you can use methods such as LaunchUriAsync or LaunchFileAsync
Without TabTip.exe
I recognize you are trying to show the on-screen keyboard judging by the path of the exe. I suggest a better approach would be to trigger the new touch-enabled keyboard which is easily possible without additional hassle from UWP with InputPane API:
var pane = InputPane.GetForCurrentView();
pane.TryShow();
With TabTip.exe
If you prefer the older on-screen keyboard for some reason, you have two problems with your existing code.
Firstly, ms-appx: scheme is used to refer to files at the application installation path. The path you require is an absolute path, so you can't use it there.
Secondly, as this is an arbitrary path on the hard drive, you don't have access to it directly (as UWP apps run in a sandbox and can't access the filesystem directly for security reasons). To access the file, you will need to declare the broadFileSystemAccess capability, which will then allow you to initialize the StorageFile instance. You can check for example this SO question to learn how to do just that.
Note: I don't have my VS PC around so I can't say for sure if this will allow you to launch the executable or not, as that seems like an additional permission which may not be granted. In case this fails, I strongly recommend the first solution.
Make sure you edited the manifest file and add the extension for full trust process in the application.

Why do chrome/visual studio code/edge all have the same classname "Chrome_WidgetWin_1"?

I tried to enumerate all Win32 children of the Desktop handle, then tried to print out each child's class name using GetClassNameW(childHandle).
The chrome browser's class name is "Chrome_WidgetWin_1". However, the Edge browser's class name and Visual Studio Code's class name are also "Chrome_WidgetWin_1".
Why is that so? Why does Microsoft decide to use the same class name as Chrome for them?
Window classes registered without CS_GLOBALCLASS in different processes are technically not the same classes even though the names might be the same.
These class names are internal details that you should not rely on but in this case they are the same because they are all using Chromium based browsers to drive their UI. Visual Studio Code is an Electron app (uses Chromium) and it is well known that Edge changed from custom Microsoft code to Chromium.

Open default application with nativescript

I am quite surprised I have yet to find an answer to this on the internet.
How do I open a native/default app from my nativescript app?
In this instance I want to open a map application with a location parameter (not sure if it will be a string, coordinates, etc).
You can use utils
var utilsModule = require("tns-core-modules/utils/utils");
utilsModule.openUrl("<< for example: maps short link>>");
In fact it will try to open map link with browser. But android && ios will ask to you “do you want to open it via Maps?” at first.
There may be some plugins for opening via maps directly without any question but I think this way is better (you dont need to install a plugin)
For more info about utils, see that

reason = "The model used to open the store is incompatible with the one used to create the store"

i am creating os x app with core data. when i am modify the model. the error occurred that is showed in the image. the reason shown is "The model used to open the store is incompatible with the one used to create the store"; how to fix this error. this same error i fixed by clearing the simulator in iOS app . how to fix this in os x app.
enter image description here
If you look at the code that sets up your persistentStoreCoordinator, it should tell you where the storage for your objects is located and the file name. (The default location from the Apple template is provided by the applicationDocumentsDirectory method inside the app delegate.)
The usual location for the data store of a non-document-based Core Data application is in ~/Library/Application/Support/com.mydomain.myapp/CocoaAppCD.storedata.
Rename or delete this file (depending on whether its contents are disposable).
Re-launching your application will recreate the file with no data and you can start re-populating it according to your new model.
With production versions of your application, a model change would require a formal lightweight or heavy migration to preserve the user's data.
As a convenience, on startup I print out the location of the database to the console as follows:
// Get / print location of database for use in testing / debugging
let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let path = paths[0] + "/LocalStore.sqlite"
print(path.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines))
Besides being easy to see, I can just select/copy/past this to use in sqliteBrowser.
Choose Finder and go to Library from Go by clicking option button on keyboard. then search on library using your app Bundle Identifier. delete the folder with it. then Re-launching your application will recreate the folder with no data and you can start re-populating it according to your new model.

Quickly find the full path to an app whose name contains a specific phrase

I'm working on a little app that acts as a plugin for a 3rd party app. For it to function, I need to access a saved file from the 3rd party app ("other app" from here). In newer versions, the other app keeps this in ~/Application Support/Test App/Saved Files/.
This is easy to go to, using something like this:
NSString *savedFiles = [NSHomeDirectory() stringByAppendingPathComponent:#"~/Application Support/Test App/Saved Files"];
But I also want to make it compatible with older versions, and they don't use the application support folder. Older versions went in their folder in the user's applications folder, for example this structure:
~/Applications/Test App/Test App.app
~/Applications/Test App/Saved Files/
I can use the same as above to find the location to saved files. But the app won't always be installed here, or the folder name could be different in a different language. This is the problem.
I thought so far, I thought the following are options to get the path:
Ask the user to navigate to the file with a file selector from
within my app.
Ask the user where the "Test App.app" is, and get the
path via "../Saved Files/" relative to that.
Can the app get the path to a previously run application via the system?
Can the app use spotlight to quickly find the location?
Are there other ways to do this automatically, reliably, and quickly?
1 and 2 are not preferred, as that would require the user to "work" to give the app the path. What do you all think?
Are there other ways to automate this?
Which would be the fastest?
You can try to ask LaunchServices for the app's location, given its bundle identifier with the LSFindApplicationForInfo call:
CFURLRef urlRef = NULL;
LSFindApplicationForInfo(kLSUnknownCreator, (CFStringRef)#"com.example.some-app", NULL, NULL, &urlRef);
NSLog(#"URL: %#", (__bridge id)urlRef);
This assumes that the bundle identifier is the same between the two variants you mention. If it's really just the name that is the same, you could query by name instead:
CFURLRef urlRef = NULL;
LSFindApplicationForInfo(kLSUnknownCreator, NULL, (CFStringRef)#"Test App.app", NULL, &urlRef);
NSLog(#"URL: %#", (__bridge id)urlRef);

Resources