How i get URL of steam apps in c# - c#

I'm making a application for steam games. Because shortcuts steal zone from desktop ,so i make this project for this. I want add a "drop file here to add list" when he put to shortcut on program i need get the app id, then it will automatically add to list.I added the drop file script!! But i dont know how to get URL title from assembly..There is a screenshot. I want get url from shortcut like this.
SCREENSHOT 1
SCREENSHOT 2
!! I made the drop file script.. I just have problems at get url script.

Opening steam applications is very simple, if you know the location of your steam.exe.
System.Diagnostics.Process.Start(#"C:\Program Files (x86)\Steam\steam.exe","steam://rungameid/730");
In my case (i think its default as well) you can start an application just by giving the path of the steam.exe and passing the content of the shortcut as argument.
Edit:
If you want to get the argument value you can just read the File using
File.ReadAllLines(path);
And get the argument from the string, which will then look like this:
string[] lines = File.ReadAllLines(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/Golf With Your Friends.url");
string argument = lines.ToList().FirstOrDefault(item => { return item.Contains("steam://"); }).Replace("URL=", "");
System.Diagnostics.Process.Start(#"C:\Program Files (x86)\Steam\steam.exe", argument);

Related

How do I overwrite a text file line by line using StreamWriter WriteLine in c#

As part of my c# learning, I have a simple game on a console application. I have now added a text file to record the top score. It has 4 lines, date, number of attempts, time in minutes and additional time in seconds. The text file is part of the project solution, and although I don't specify the full path, I can read the file with StreamReader and output the lines without any trouble. But if I have a new top score, and I wish to overwrite the values in the text file, nothing is happening. The text file remains unmodified.
I have tried using StreamWriter. It feels somewhat intuitive to use StreamReader ReadLine to bring the data into the application and StreamReader WriteLine to output. But the output piece is not working. For my sins, this is my code. There are some similar queries on stackooerflow, but I've not found a solution that appears to fit my query.
if (newBestScore== true)
{
DateTime dateToday = DateTime.Now;
string dateString=dateToday.ToShortDateString();
string currAttempts=CurrentAttempts.ToString();
using (StreamWriter newTopScore = new StreamWriter("TopScore.txt"))
{
newTopScore.WriteLine(dateString);
newTopScore.WriteLine(currAttempts);
newTopScore.WriteLine(timeTaken.Minutes);
newTopScore.WriteLine(timeTaken.Seconds);
newTopScore.Close();
}
}
I'll not fix your problem, but I'll tell you how you can fix all problems of this sort by yourself in the future.
Download Process Monitor and add a filter for your application, like so:
Process Name, contains, <myapp>.exe then Include and then add this filter by pressing the Add button.
Then start recording and look for TopScore.txt and see in which directory it looks for that file. You can use the find dialog for that (Ctrl+F):
Then have a look at the full file name of that file, so you know where it it being written. You can even right click and choose "Jump to ...".
Understand what a working directory is. The file will be written in the working directory if you didn't provide a full path.
Why go this way? This way proves that you have a problem independently. You don't change the source code. Whenever you change the source code and e.g. add diagnostics code like Console.WriteLine(Path.GetFullPath(...));, problems may disappear.

Selenium c# https://baseurl/config/dteg/vt2k/standard/vt2k-dev-standard.txt I want to extract vt2k-dev-standard.txt

when I press an icon in my application, it automatically generates a file and opens its contents in the url in a new tab or current tab whichever way you look at it
https://BASEURL/config/dteg/vt2k/standard/vt2k-dev-standard.txt
I want to read in the full url and extract the last filename and store it in a string. Can you please help me?
Thank you
I haven't tried anything yet. Anything I have tried either gets the previous url in old tab or just simply gets the base url.
Found out what I was looking for. For everyone who don't know here is the code:
Uri uri = new Uri("https://BASEURL/config/dteg/vt2k/standard/vt2k-dev-standard.txt");
string lastSegment = uri.Segments.Last();

Shortcut of universal app

I'm creating a Xamarin.Forms app and I want to have an option to create a Desktop shortcut (I already implemented on Android).
I have a protocol that I can use to launch my app, so this is not a concern, and I already saved another type of file in the Desktop to test, my only problem is that I can't create a .lnk file.
In my researches I saw a lot of explanations as to how to create a .lnk file programmatically, but all tutorials were related to WindowsForms or PowerShell scripts (as far as I know, UWP doesn't allow executing PS scripts).
So, is there a way of creating Desktop Shortcuts?
Edit after answer
When I create the shortcut using the Dialog, everything is fine, but when I create it in the app, the shortcut's icon doesn't change to my app's icon, it displays a confirmation when I run it and after I confirm, it displays an error message saying The target "" of this Internet Shortcut is not valid.
But if I change the file in any way (rename it, copy and paste it or change it's contents), it changes the icon to the correct one and when I confirm the dialog, it opens my app as expected. This proves that nothing is wrong with the file or its contents, but I don't know how to workaround this.
Edit
StorageFile shortcutFile = null;
try
{
shortcutFile = await ApplicationData.Current.LocalFolder.GetFileAsync("shortcut.url");
}
catch (Exception) { }
if (shortcutFile == null)
{
shortcutFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("shortcut.tmp", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteLinesAsync(shortcutFile, new string[] { "[InternetShortcut]", "URL=yourapp:///" });
string newShortcutName = shortcutFile.Path.Substring(0, shortcutFile.Path.Length - 4) + ".url";
File.Move(shortcutFile.Path, newShortcutName);
shortcutFile = await ApplicationData.Current.LocalFolder.GetFileAsync(newShortcutName.SplitWithoutEmpty('\\').Last());
}
FolderPicker savePicker = new FolderPicker
{
SuggestedStartLocation = PickerLocationId.Desktop
};
savePicker.FileTypeFilter.Add(".url");
StorageFolder folder = await savePicker.PickSingleFolderAsync();
if (folder != null)
{
// Works fine until here, then it throws an exception (Permission Denied)
await shortcutFile.CopyAsync(folder, shortcutFile.Name);
}
The Windows 10 alternative to desktop shortcut is a Live Tile, which is basically a live version of an Android icon. You can create a desktop shortuct by dragging the Live Tile to the desktop manually.
If you want a programmatic way and have already a registered URI protocol, you should be able to create a url shortcut instead of classic one. Let's see this step by step:
You can create a URL shortuct manually using the dialog:
Now this will create a .url file on your desktop, which behaves as a shortcut. You can see it in the listing of dir command:
Now try to rename the file to have a different extension using the ren command, for example:
ren YourApp.url YourApp.urltext
You can now open this file normally in a text editor to see its contents:
[{000352A0-0000-0000-C000-000000000012}]
Prop3=19,0
[InternetShortcut]
IDList=
URL=yourapp:///
From my testing it seems that the first two rows are unnecessary and the IDList property is also redundant. This means you can just do with the following:
[InternetShortcut]
URL=yourapp:///
If you rename the file back to have .url extension and double-click it, it will launch the app associated with the yourapp protocol, which is exactly what you need.
So to do this programmatically, you have to save a .url file with the contents we just came up with and save it where the user wants to have the shortcut created.
There is one disadvantage, that you have to keep in mind - UWP apps are sandboxed, so you cannot directly create files on desktop without the user's consent. The best approach I can see now is to use a FileSavePicker to let the user choose a folder where she wants to save the shortcut. It is still quite user friendly and it even gives her the flexibility to have the shortcut elsewhere than on the desktop.
Update
I have found this SO answer with an extremely detailed analysis of this problem. It thoroughly explains why we are hitting these problems - the URL files are interpreted by Internet Explorer and once interpreted, the URL info is stored as NTFS metadata. I would suggest creating the file with a temporary extension first and only then rename it to .url. I am not at my computer right now, but I will try when I get there :-)
Update 2
After some playing I have come up with the following and it "partially works on my PC". The shortcut is successfully created and even has the right icon, BUT each time it is opened it shows the "file from different computer" confirmation dialog, which can be turned off only through Properties.
FileSavePicker savePicker = new FileSavePicker
{
SuggestedStartLocation = PickerLocationId.Desktop
};
savePicker.FileTypeChoices.Add("Shortcut", new [] { ".url" });
var saveFile = await savePicker.PickSaveFileAsync();
if (saveFile != null)
{
await FileIO.WriteLinesAsync(
saveFile,
new string[] { "[InternetShortcut]", "URL=yourapp:///" });
}
I have found a much simpler way.
You just need to create a normal shortcut with the target
C:\Windows\explorer.exe shell:AppsFolder{PackageFamilyName}!App
I use the following code to generate the shortcut the first time the application runs (You'll need to add a COM reference to Windows Scripting Host):
string shortcutLocation = Path.Combine(Environment.SpecialFolder.Desktop, shortcutName + ".lnk");
WshShell shell = new();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.IconLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icon.ico");
shortcut.Arguments = $"shell:AppsFolder\\{insert your PackageFamilyName}!App";
shortcut.TargetPath = Path.Combine(Environment.GetEnvironmentVariable("windir"), "explorer.exe");
shortcut.Save();
PackageFamilyName:
Your app family name should be a giant alphanumeric hash, the easiest way to get that is to install it somewhere and use the powershell command Get-AppxPackage https://learn.microsoft.com/en-us/powershell/module/appx/get-appxpackage?view=windowsserver2019-ps. It can also be obtained in code with Package.Current.Id.FamilyName.
Icon location: This is not necessary it should use the default icon for your app. I changed this because it used a version with an ugly blue background. Adding an icon to your build output folder and linking it as above lets you choose the icon.
It should also be noted that the mouseover text for the shortcut is windows explorer. Please let me know if anyone finds a way around this.
Another option might be to add an ExecutionAlias and create the shortcut directly to the alias.
In Package.appxmanifest
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
<Extensions>
<uap5:Extension Category="windows.appExecutionAlias" EntryPoint="Windows.FullTrustApplication" Executable="MyApp\MyApp.exe">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="MyApp.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
</Extensions>
Then make the shortcut for MyApp.exe

How to make a C# Application work as the default program for certain files? [duplicate]

This question already has answers here:
Register file extension in window registry?
(3 answers)
Closed 8 years ago.
My application has a picture box in it. When I open an image in Windows, instead of the default program that opens to show that image, I want to use my own application and have that program containing the picture box show the image.
I did this recently, though I used a different action, not the default Open action.
First you find out file type of some extension, say .jpg:
var imgKey = Registry.ClassesRoot.OpenSubKey(".jpg")
var imgType = key.GetValue("");
Then you find out the path to your executable and build the "command string":
String myExecutable = Assembly.GetEntryAssembly().Location;
String command = "\"" + myExecutable + "\"" + " \"%1\"";
And register your executable to open files of that type:
String keyName = imgType + #"\shell\Open\command";
using (var key = Registry.ClassesRoot.CreateSubKey(keyName)) {
key.SetValue("", command);
}
You need to make some registry entries. First you need to associate the file extension with a class name (class name can be anything, just make it up).
So for example, if I wanted to associate .foo extensions with my Blah.exe program I would create the following registry entries (Note: In this case I'm associating .foo with a class called Foo.Document, then associated that class with my program):
Key: HKLM\SOFTWARE\Classes\.foo
Value: <default> = “Foo.Document”
Key: HKLM\SOFTWARE\Classes\Foo.Document
Value: <default> = “Foo Document”
Key: HKLM\SOFTWARE\Classes\Foo.Document\shell\open\command
Value: <default> = “[blah.exe]” “%1″
Your scenario makes me think that it's perfectly possible for you to simply select any JPG file, right click on the file, select "Open with" --> Choose default program, browse to your C# program and select the option "Always use the selected program to open this kind of file"
If you feel that you need to do this programmatically, you would need to set this on the Registry.
Here's a SO link that shows the process.
To set your app as default one for Jpeg files (example), you could:
Using Regedit.exe and goto item HKCR\.jpg\ and create subfolders like this shell\open\command.
Create there a new string value and edit default value as "path_to_exe" "%1"
Edit your EXE so that it can read arguments passed on command line and, if there is one, open it in picturebox (yeah, and many other controls as file does exists, file can be loaded in picturebox, etc...)

c# playing movie in windows media player "Not" embedded

I have looked around, everything I find is talking about embedding it.
I do not want to embed it. I want to click a button and launch windows media player seperatly.
For example, I have a location saved in XML file. I have a right click to click Play. It pulls the location. like so.
int dd = dataGridView1.CurrentRow.Index;
string eLoc = dataGridView1.Rows[dd].Cells[4].Value.ToString();
if (eLoc == "")
{
MessageBox.Show("You have not saved a location for this movie","Movie Play",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show(eLoc);
ProcessStartInfo ps = new ProcessStartInfo("wmplayer.exe", eLoc.ToString());
Process.Start(ps);
}
As you can see, I have a pop up to view, what the string is.
It is this. I added %20 to replace spaces, thinking that was the problem but it isn't.
As you can see it pulls the full location. All I get back from windows media player is this.
Any ideas? To me it seems like this should be working..
I got it working now. It was the spaces causing the errors, I changed to this, and works perfect now.
ProcessStartInfo ps = new ProcessStartInfo("wmplayer.exe", "\""+eLoc+"\"");
It should be working, in fact on my computer and with a different path it does work, I suspect the file is damaged like jfs suggested.

Categories

Resources