I am developing a UWP app for the first time. I always used Windows Forms and WPF, but the potential design of these apps is gorgeous, but the problem is they are kind of sandbox, especially for my current project. Basically, I am making a games launcher, where you add your games and the program creates a list of games. (Think of it like a Steam for everything with a modern Windows 10 Material design).
Now, I managed to do almost everything, but two things. First, and most important, is getting the path to the game. I create a file picker, I can pick the .exe files, I can get their names, but the file.Path property doesn't work, it returns a null path. I thought this might be because of UWP's sandboxed design, but I got far into this, that I really don't want to abandon it.
The second problem would be the launching of these files. I managed to do it on Steam games using Steam's specific URI. ("steam://rungameid/xxxxxx" where xxxxxx is the game id) But it doesn't work if I just put a path as a URI.
What do you think? Are there any solutions? Let me show you some of the related code:
public async void SelectEXE()
{
var picker = new Windows.Storage.Pickers.FileOpenPicker
{
ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
};
picker.FileTypeFilter.Add(".exe");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
stuffWrite[0] = file.Name;
stuffWrite[1] = file.Path;
count++;
WriteCount();
WriteItem(count, string.Join(",", stuffWrite));
UpdateList();
}
}
async void LaunchGame(string uriToLaunch)
{
Uri uri = new Uri(uriToLaunch);
games_list.Items.Add(uriToLaunch);
uri = new Uri("steam://rungameid/730"); //replace with actual path
await Windows.System.Launcher.LaunchUriAsync(uri);
}
Sandbox restrictions make it so that getting the path from that property will not reliably work, as Ahmed pointed out.
As for launching, you can't launch exe files directly from a UWP app. It's simply not possible as it is explicitly restricted from doing so by design. Some workaround solutions to your problem:
Use Steam to launch non-Steam games. You can add non-Steam shortcuts and this creates a SteamID based on the file's path so you can launch it from the UWP app using a URI. I found the algorithm to launch any exe using the Steam URI scheme from this board post and follow the link to the person's Python project source code.
Create a helper Win32 app that does the launching for you. In my app suite I communicate between the UWP and Win32 using WebSocket. There are also new solutions to integrate Win32 apps into UWP like Desktop Bridge and full trust Win32.
Use a 3rd party scripting tool like AutoHotkey. Have your UWP app generate the string of a script to launch the game, and save the text file with extension that launches that script language by default. You can then use the Launcher class to launch the file, which the scripting app will open with by default and then it will launch the game. I doubt your app would be accepted on the Windows Store if you did this.
Consider not using UWP at all. There are some libraries to make WPF look more modern as I'm sure you know.
Related
I'm writing UWP app (C# and C++/CX).
My app gives user an opportunity to save video recorded by some connected camera.
I use OpenCV VideoWriter for it because I have to add video effects to C# SoftwareBitmap (comes to me from MediaFrameReader).
Thats how I'm creating VideoWriter in C++/CX code:
videoWriter.open(
pathToCreatedFile, // Works with "videos", but not with "desktop" or other
encodingProperties.codec,
encodingProperties.fps,
cv::Size{ (int)frameSize.Width, (int)frameSize.Height }
);
If I pick default Windows "Videos" library for saving, everything is good, but when I try to use "Desktop" folder for example or any other specific location, my output .mp4 file is 0KB.
Is it possible to save file in random directory in UWP and how can I reach it?
P.S. My minimal version is November update.
By design, you don't have access to arbitrary file folders from a UWP. You can request specific media libraries via a declared capability easily: documentsLibrary, documentsLibrary, picturesLibrary, and/or picturesLibrary.
There is no option for accessing the desktop directly.
The broadFileSystemAccess capability would allow this, but this is a restricted capability which means it will be difficult to publish it to the Windows Store (if that's your plan).
See Microsoft Docs.
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.
This is not a question about standard localization - I know how to localize the app, use resources, Uid's and so on - this works perfectly.
The problem is that the app comes within a bundle, therefore when the user installs the app it covers only languages that are selected in device/phone settings. But I would like to provide an option in settings that would allow choosing a language regarding the settings. For this purpose, I can use ApplicationLanguages.PrimaryLanguageOverride, which works very nice when deployed via VS, but as I've mentioned - version from the store lacks resources, as not all are installed.
Does anybody know how to bypass this bundle behavior?
The problem is also that I'm using MAT (multilingual app toolkit) and my translation comes with xliff files. I've spent quite a lot of time to find a way to convert them to resw files, without success. Is there any way to do it (or I've to write my own converter)?
You need to use ResourceContext:
var context = new ResourceContext(); // deliberately not using getForCurrentView()
context.Languages = new string() {"fr-fr"};
ResourceMap resourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
String str = resourceMap.GetValue("string1", context).ValueAsString;
More info at:
'How to load string resources' and
'ResourceContext class'ResourceContext class'.
PS. I have app in store and there is no problem with changing language without reinstall so all resources must be there
Check out this: UWP: Resource file for languages is not deployed correctly you need to get rid of bundle in order for my code from above to work. Or you could check if chosen language is installed in OS and if not you could not allow user to choose it using:
Windows.System.UserProfile.GlobalizationPreferences.Languages
this might be a stupid question, but I just can't seem to figure out how to access my text files that I embedded in my app. I know several ways to do it for desktop apps (through searching for ways to do it for rt apps) but have never found a way to do it for rt apps. This has been bugging me for MONTHS!
Anything in your app package can be referred to using an ms-appx:/// URI (the three /// are important), and opened with StorageFile.GetFromApplicationUriAsync (a static method, see http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.getfilefromapplicationuriasync.aspx).
You can also get your package's StorageFolder object through Windows.ApplicationModel.Package.InstalledLocation, see http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.package.installedlocation.aspx. Then you use StorageFolder.GetFileAsync (http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefolder.getfileasync.aspx) with a relative pathname.
I'm very new to Visual Studio 2010. I decided to create a simple WFA with C#.
Everything work fine with Images and Audio playback. My intention is to create a standalone application and send it to my friend as a gift. Problem I facing now is that when I tried to publish the application, the Images / Audio is still using the same location in my PC. So it won't play nor display any images.
Any comment on this or guide for me? I did try search for solution but doesn't seems to have any luck.
This is the code that I used to play Audio :
SoundPlayer ply = new SoundPlayer(#"C:\Users\Liam619\Documents\Visual Studio 2010\Projects\BirthdayApp\BirthdayApp\Resources\BirthdaySong.wav");
If I remove or change the path, the Application will hit error for locating the Audio file.
There may be several solutions to your problem.
a) embed the sound into a resource. As a beginner, resources may be a bit tricky to get it right the first time. But I want to encourage you reading something about it. You'll need resources when you want to translate your first program.
b) create an installer which copies the sound file to the installation directory. Try InnoSetup. If you're a programmer, sooner or later, you'll need to create a Setup anyway. Always worth knowing how to do that.
In that case, you still need the path to the sound file, but if you install your EXE into the same path as the sound file, see getting the application's executable directory.
everything in the database whether images or audio refers to your own server database.you have to send the database too with the app and the correct version .NET framework needs to be installed on the target PC.