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

Add a silent Install option via -s #4

Merged
merged 1 commit into from
May 6, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 38 additions & 21 deletions git-credential-winstore/Program.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Program


static void Main(string[] args) static void Main(string[] args)
{ {
TryLaunchDebugger(ref args); TryLaunchDebugger(ref args);
if (TrySilentInstall(ref args)) { return; }


// Parse command // Parse command
Func<IDictionary<string, string>, IEnumerable<Tuple<string, string>>> command = null; Func<IDictionary<string, string>, IEnumerable<Tuple<string, string>>> command = null;
Expand Down Expand Up @@ -61,6 +62,19 @@ private static void TryLaunchDebugger(ref string[] args)
Debugger.Launch(); Debugger.Launch();
args = args.Skip(1).ToArray(); args = args.Skip(1).ToArray();
} }
}

private static bool TrySilentInstall(ref string[] args)
{
if (args.Length > 0 && args[0] == "-s")
{
Console.Out.WriteLine("Silently Installing...");
InstallTheApp(true);
args = args.Skip(1).ToArray();
return true;
}

return false;
} }


private static void WriteGitParameters(IDictionary<string, string> response) private static void WriteGitParameters(IDictionary<string, string> response)
Expand Down Expand Up @@ -88,26 +102,29 @@ private static void WriteUsage()
Console.Error.WriteLine("If you see this. git-credential-winstore is correctly installed!"); Console.Error.WriteLine("If you see this. git-credential-winstore is correctly installed!");
Console.Error.WriteLine("This application is designed to be used by git as a credential helper and should not be invoked separately"); Console.Error.WriteLine("This application is designed to be used by git as a credential helper and should not be invoked separately");
Console.Error.WriteLine("See the following link for more info: http://www.manpagez.com/man/1/git-credential-cache/"); Console.Error.WriteLine("See the following link for more info: http://www.manpagez.com/man/1/git-credential-cache/");
} }


private static void InstallTheApp() private static void InstallTheApp(bool silent = false)
{ {
if (MessageBox.Show("Do you want to install git-credential-winstore to prompt for passwords?", if(!silent)
"Installing git-credential-winstore", MessageBoxButtons.YesNo) != DialogResult.Yes) {
{ if (MessageBox.Show("Do you want to install git-credential-winstore to prompt for passwords?",
return; "Installing git-credential-winstore", MessageBoxButtons.YesNo) != DialogResult.Yes)
} {

return;
var target = new DirectoryInfo(Environment.ExpandEnvironmentVariables(@"%AppData%\GitCredStore")); }
if (!target.Exists) }
{
target.Create(); var target = new DirectoryInfo(Environment.ExpandEnvironmentVariables(@"%AppData%\GitCredStore"));
} if (!target.Exists)

{
var dest = new FileInfo(Environment.ExpandEnvironmentVariables(@"%AppData%\GitCredStore\git-credential-winstore.exe")); target.Create();
File.Copy(Assembly.GetExecutingAssembly().Location, dest.FullName, true); }


Process.Start("git", "config --global credential.helper !~/AppData/Roaming/GitCredStore/git-credential-winstore"); var dest = new FileInfo(Environment.ExpandEnvironmentVariables(@"%AppData%\GitCredStore\git-credential-winstore.exe"));
File.Copy(Assembly.GetExecutingAssembly().Location, dest.FullName, true);

Process.Start("git", "config --global credential.helper !~/AppData/Roaming/GitCredStore/git-credential-winstore");
} }


static IEnumerable<Tuple<string, string>> GetCommand(IDictionary<string, string> args) static IEnumerable<Tuple<string, string>> GetCommand(IDictionary<string, string> args)
Expand Down