Exemplo n.º 1
0
 private void DeleteProfile(string name)
 {
     ExecuteUiAction(() =>
     {
         SettingsFiles.ApplicationSettings.SetHotkey(name, Keys.None);
         SettingsFiles.SaveApplicationSettings();
         ProfileFiles.DeleteProfile(name);
     }, "Could not delete display profile " + name);
 }
Exemplo n.º 2
0
 public static void EnsureCreated()
 {
     ProfileFiles.EnsureCreated();
     try
     {
         ApplicationSettings = JsonConvert.DeserializeObject <ApplicationSettings>(File.ReadAllText(ApplicationSettingsFilename), Profile.JsonSerializerSettings);
     }
     catch
     {
         ApplicationSettings = new ApplicationSettings();
     }
 }
Exemplo n.º 3
0
        private void Rebuild()
        {
            if (_contextMenuIsOpen)
            {
                RequestRebuild();
                return;
            }

            // Load all profile files
            _profiles.Clear();
            var profiles = ProfileFiles.GetProfileNames();

            foreach (var name in profiles)
            {
                _profiles.Add(name, Exceptional.Create(() => ProfileFiles.LoadProfile(name)));
            }

            BuildTrayMenu();
            RefreshHotkeys();
        }
Exemplo n.º 4
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string profileName;

            if (powerpointMode.IsChecked == true)
            {
                profileName = "POWERPOINT";
            }
            else if (propresenterMode.IsChecked == true)
            {
                profileName = "PROPRESENTER";
            }
            else
            {
                return;
            }

            {
                DisplaySettings profile;
                try
                {
                    profile = ProfileFiles.LoadProfile(profileName);

                    var extraMessage = profile.MissingAdaptersMessage();
                    if (extraMessage != "")
                    {
                        Console.Error.WriteLine("Warning: " + extraMessage);
                    }
                    profile.SetCurrent();
                } catch (System.IO.FileNotFoundException ex)
                {
                    var m = new MessageBox();
                    m.ShowMessage(this, "Profiles are missing", "To fix this error", "Create the POWERPOINT and PROPRESENTER profiles from DisplayProfilesGui.exe");
                } catch (Exception ex)
                {
                    var m = new MessageBox();
                    m.ShowMessage(this, "Error", "Something happened", ex.Message);
                    throw;
                }
            }
        }
Exemplo n.º 5
0
 private void SaveProfile(string name)
 {
     ExecuteUiAction(() => ProfileFiles.SaveProfile(name),
                     "Could not save display profile " + name);
 }
Exemplo n.º 6
0
        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);
            }
        }