private void SaveProfile(string name) { ExecuteUiAction(() => ProfileFiles.SaveProfile(name), "Could not save display profile " + name); }
static int Main() { var context = ""; try { ProfileFiles.EnsureCreated(); var options = OptionParser.Parse <Options>(Environment.CommandLine.Lex().Skip(1)); if (options.Command == Options.ListCommand) { OptionParser.Parse <ListOptions>(options.CommandArguments); context = "Could not list profiles: "; Console.WriteLine("Profile list:"); foreach (var name in ProfileFiles.GetProfileNames()) { Console.WriteLine(" " + name); } } else if (options.Command == Options.SaveCommand) { var saveOptions = OptionParser.Parse <SaveOptions>(options.CommandArguments); context = "Could not save profile " + saveOptions.Name + ": "; ProfileFiles.SaveProfile(saveOptions.Name); Console.WriteLine("Successfully saved profile " + saveOptions.Name); } else if (options.Command == Options.LoadCommand) { var loadOptions = OptionParser.Parse <LoadOptions>(options.CommandArguments); context = "Could not load profile " + loadOptions.Name + ": "; var profile = ProfileFiles.LoadProfile(loadOptions.Name); var extraMessage = profile.MissingAdaptersMessage(); if (extraMessage != "") { Console.Error.WriteLine("Warning: " + extraMessage); } profile.SetCurrent(); Console.WriteLine("Successfully loaded profile " + loadOptions.Name); } else if (options.Command == Options.DetailCommand) { var detailOptions = OptionParser.Parse <DetailOptions>(options.CommandArguments); context = "Could not display details for profile " + detailOptions.Name + ": "; var profile = ProfileFiles.LoadRawProfile(detailOptions.Name); var pathComparer = ComparerBuilder.For <NativeMethods.DisplayConfigPathInfo>() .OrderBy(x => profile.ModeInfo[(int)x.sourceInfo.modeInfoIdx].sourceMode.position.x) .ThenBy(x => profile.ModeInfo[(int)x.sourceInfo.modeInfoIdx].sourceMode.position.y); foreach (var adapterPath in profile.PathInfo.OrderBy(x => x, pathComparer).GroupBy(x => x.sourceInfo.adapterId)) { var sourceAdapterId = adapterPath.Key; var sourceAdapter = profile.Adapters[sourceAdapterId]; Console.WriteLine(sourceAdapter + ":"); foreach (var path in adapterPath) { var targetAdapterId = path.targetInfo.adapterId; var targetAdapter = profile.Adapters[targetAdapterId]; var target = targetAdapter.Targets[path.targetInfo.id]; var line = " " + target; if (sourceAdapterId != targetAdapterId) { line += " (" + targetAdapter + ")"; } line += " "; var sourceMode = profile.ModeInfo[(int)path.sourceInfo.modeInfoIdx]; line += sourceMode.sourceMode.width + "x" + sourceMode.sourceMode.height; line += " offset " + sourceMode.sourceMode.position.x + "," + sourceMode.sourceMode.position.y; line += " @" + Math.Round(path.targetInfo.refreshRate.numerator / (double)path.targetInfo.refreshRate.denominator, 2) + "Hz"; Console.WriteLine(line); } } } else if (options.Command == Options.ValidateCommand) { var validateOptions = OptionParser.Parse <ValidateOptions>(options.CommandArguments); context = "Could not validate profile " + validateOptions.Name + ": "; var profile = ProfileFiles.LoadProfile(validateOptions.Name); var ex = profile.Validate(); if (ex == null) { Console.WriteLine("Profile " + validateOptions.Name + " passed validation."); return(0); } Console.WriteLine("Profile " + validateOptions.Name + " failed validation:"); Console.WriteLine(ex.Message); var extraMessage = profile.MissingAdaptersMessage(); if (extraMessage != "") { Console.WriteLine(extraMessage); } return(1); } return(0); } catch (OptionParsingException ex) { Console.Error.WriteLine(ex.Message); Options.Usage(); return(-2); } catch (Exception ex) { Console.Error.WriteLine(context + ex.Message); return(-1); } }