Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more friendly to scripts #62

Merged
merged 2 commits into from Oct 16, 2019
Merged

Be more friendly to scripts #62

merged 2 commits into from Oct 16, 2019

Conversation

eroen
Copy link
Contributor

@eroen eroen commented Sep 29, 2019

These changes make running DepotDownloader from a script less of a hassle.

I'm new to C#, so please carefully review the changes and bear with me if my solutions are not idiomatic. I'd love to get feedback!

This is beneficial for scripts that don't want to expose the password in the
command line arguments.
@azuisleet
Copy link
Member

Looks good, I think my only question is about the error messages as exceptions. Could we also attach a bool or int status return to those Tasks as well? I'd prefer not to have a stack trace for those common cases.

password = Util.ReadPassword();
Console.WriteLine();
}
// Fallback to support redirected input
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use Console.IsInputRedirected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know it existed, thanks! I didn't see your comments until I pushed a new revision below, but I'll look at it when I have time again.

@@ -403,7 +403,7 @@ public static async Task DownloadAppAsync( uint appId, uint depotId, ulong manif
{
string contentName = GetAppOrDepotName( INVALID_DEPOT_ID, appId );
Console.WriteLine( "App {0} ({1}) is not available from this account.", appId, contentName );
return;
throw new Exception(String.Format("App {0} ({1}) is not available from this account.", appId, contentName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the throws to a custom exception now, in order to catch them but not interfere with unexpected and thus interesting exceptions and their tracebacks.

My original idea was to just raise unhandled exceptions for unhandled errors, letting someone else change it to a more specific exception if they wanted to catch it at a later time (this would be bad in a library, but I don't expect anyone to reuse DepotDownloader in that way). Other parts of the code seem to use Exception() for this already.

On a related note, do you know if the linter that gives this warning is available with the dotnet cli tools? I don't have a VisualStudio setup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, we just haven’t configured it (yet).

@@ -11,14 +11,14 @@ namespace DepotDownloader
class Program
{
static void Main( string[] args )
=> MainAsync( args ).GetAwaiter().GetResult();
=> System.Environment.Exit( MainAsync( args ).GetAwaiter().GetResult() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw you can make the method signature int here and just return the int, there's no need to call Environment.Exit from the main function.

@azuisleet
Copy link
Member

The revised exceptions look good. Console.IsInputRedirected should be investigated to see if it's implemented and working.

When run by a script, the script needs to know if the requested operation was
succesful.

This patch makes sure error codes are returned for a number of unhandled error
conditions.
@eroen
Copy link
Contributor Author

eroen commented Oct 10, 2019

Thanks for bearing with me, I pushed a new revision with the changes you requested.

@azuisleet azuisleet merged commit da88425 into SteamRE:master Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants