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);
}