当前位置: 首页>>代码示例>>C#>>正文


C# Settings.write方法代码示例

本文整理汇总了C#中Settings.write方法的典型用法代码示例。如果您正苦于以下问题:C# Settings.write方法的具体用法?C# Settings.write怎么用?C# Settings.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Settings的用法示例。


在下文中一共展示了Settings.write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static int Main( string[] arguments )
        {
            int widthMaximum = Console.LargestWindowWidth - 4;
            int widthMinimum = 8;
            int heightMaximum = Console.LargestWindowHeight - 1;
            int heightMinimum = 1;

            string file;
            Settings settings;
            int value;
            StringBuilder error = new StringBuilder();

            int? width = new int?();
            int? height = new int?();
            bool? center = new bool?();
            bool writeToConfig = false;
            bool skipWidth = false;
            bool skipHeight = false;
            bool skipCenter = false;

            app = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
            appLen = Math.Max((app + ".exe").Length, 9);
            appPadding = new string(' ', appLen);

            file = Assembly.GetEntryAssembly().Location + ".settings";
            settings = new Settings(file);
            settings.read();

            for (int i = 0; i < arguments.Length; i++) {
                string a = arguments[i].Trim();

                if (int.TryParse(a, out value)) {
                    value = Math.Max(value, 4);
                    if (!width.HasValue && !skipWidth) {
                        if (value > widthMaximum) {
                            Console.WriteLine("{0," + appLen + "} | the maximum width allowed for the current screen is {1} columns. using maximum instead.", "** error", widthMaximum);
                            value = widthMaximum;
                        } else if (value < widthMinimum) {
                            Console.WriteLine("{0," + appLen + "} | the minimum width allowed is {1} columns. using minimum instead.", "** error", widthMinimum);
                            value = widthMinimum;
                        }
                        width = value;
                    } else if (!height.HasValue && !skipHeight) {
                        if (value > heightMaximum) {
                            Console.WriteLine("{0," + appLen + "} | the maximum height allowed for the current screen is {1} rows. using maximum instead.", "** error", heightMaximum);
                            value = heightMaximum;
                        } else if (value < heightMinimum) {
                            Console.WriteLine("{0," + appLen + "} | the minimum height allowed is {1} rows. using minimum instead.", "** error", heightMinimum);
                            value = heightMinimum;
                        }
                        height = value;
                    } else {
                        DisplayError(settings, "unknown argument value.");
                        return 2;
                    }
                } else {
                    if (a.Equals("-")) {
                        // This separator allows the user to skip (not set) the width parameter.
                        // For example: 'shrink.exe - 60' will only change the height and not the width,
                        // much like: 'shrink.exe 100' will only change the width. (a trailing '-' here will be ignored.)
                        if (!width.HasValue) {
                            skipWidth = true;
                        } else if (!height.HasValue) {
                            skipHeight = true;
                        } else {
                            skipCenter = true;
                        }
                        continue;
                    }

                    while (a.StartsWith("-") || a.StartsWith("/")) {
                        a = a.TrimStart('-').TrimStart('/');
                    }

                    if (a.Equals("?") || a.StartsWith("h", StringComparison.CurrentCultureIgnoreCase)) {
                        DisplayCopyright();
                        DisplayHelp(settings);
                        DisplayConfig(settings);
                        return 0;

                    } else if (a.Equals("debug", StringComparison.CurrentCultureIgnoreCase)) {
                        DEBUG = true;

                    } else if (a.Equals("clear", StringComparison.CurrentCultureIgnoreCase)) {
                        settings.clear();
                        settings.write();

                    } else if (a.Equals("config", StringComparison.CurrentCultureIgnoreCase)) {
                        writeToConfig = true;
                    } else if (a.Equals("!config", StringComparison.CurrentCultureIgnoreCase)) {
                        writeToConfig = false;
                    } else if (a.Equals("center", StringComparison.CurrentCultureIgnoreCase)) {
                        center = true;
                    } else if (a.Equals("!center", StringComparison.CurrentCultureIgnoreCase)) {
                        center = false;

                    } else if (a.Equals("edit", StringComparison.CurrentCultureIgnoreCase)) {
                        LaunchUrl("notepad.exe", file);
                    } else if (a.Equals("email", StringComparison.CurrentCultureIgnoreCase)) {
                        LaunchUrl("mailto:Kody Brown <[email protected]>");
//.........这里部分代码省略.........
开发者ID:kodybrown,项目名称:shrink,代码行数:101,代码来源:shrink.cs

示例2: Main

        public static int Main( string[] arguments )
        {
            string file;
            Settings settings;
            int value;
            ConsoleUtils.WindowPosition direction = ConsoleUtils.WindowPosition.NotSet;
            int? margin = new int?();
            int? cmargin = new int?();
            int? rmargin = new int?();
            bool writeToConfig = false;

            app = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
            appLen = Math.Max((app + ".exe").Length, 9);
            appPadding = new string(' ', appLen);

            file = Assembly.GetEntryAssembly().Location + ".settings";
            settings = new Settings(file);
            settings.read();

            for (int i = 0; i < arguments.Length; i++) {
                string a = arguments[i].Trim();

                if (int.TryParse(a, out value)) {
                    if (Enum.IsDefined(typeof(ConsoleUtils.WindowPosition), value)) {
                        direction = (ConsoleUtils.WindowPosition)value;
                    } else {
                        DisplayAppName();
                        DisplayCopyright();
                        DisplayError(settings, "invalid value specified.");
                        DisplayConfig(settings);
                        return 4;
                    }

                } else if (a.Equals("restore", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.Restore;
                } else if (a.Equals("n", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("min", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.Minimized;
                } else if (a.Equals("x", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("max", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.Maximized;
                } else if (a.Equals("tr", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("topr", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.TopRight;
                } else if (a.Equals("tl", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("topl", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.TopLeft;
                } else if (a.StartsWith("u", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("t", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.Top;
                } else if (a.StartsWith("r", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("e", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.Right;
                } else if (a.StartsWith("c", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.Center;
                } else if (a.StartsWith("l", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("w", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.Left;
                } else if (a.Equals("br", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("bottomr", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.BottomRight;
                } else if (a.Equals("bl", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("bottoml", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.BottomLeft;
                } else if (a.StartsWith("d", StringComparison.CurrentCultureIgnoreCase) || a.StartsWith("b", StringComparison.CurrentCultureIgnoreCase)) {
                    direction = ConsoleUtils.WindowPosition.Bottom;

                } else {
                    while (a.StartsWith("-") || a.StartsWith("/")) {
                        a = a.TrimStart('-').TrimStart('/');
                    }

                    if (a.Equals("?") || a.StartsWith("h", StringComparison.CurrentCultureIgnoreCase)) {
                        DisplayAppName();
                        DisplayCopyright();
                        DisplayHelp(settings);
                        DisplayConfig(settings);
                        return 0;

                    } else if (a.Equals("debug", StringComparison.CurrentCultureIgnoreCase)) {
                        DEBUG = true;

                    } else if (a.Equals("clear", StringComparison.CurrentCultureIgnoreCase)) {
                        settings.clear();
                        settings.write();

                    } else if (a.StartsWith("m", StringComparison.CurrentCultureIgnoreCase)
                            || a.StartsWith("cm", StringComparison.CurrentCultureIgnoreCase)
                            || a.StartsWith("rm", StringComparison.CurrentCultureIgnoreCase)) {
                        string[] ar = a.Split(new char[] { ':' }, 2);
                        if (ar.Length != 2 || !int.TryParse(ar[1], out value)) {
                            DisplayError(settings, "invalid arguments");
                            return 5;
                        }
                        if (a.StartsWith("cm", StringComparison.CurrentCultureIgnoreCase)) {
                            cmargin = value;
                        } else if (a.StartsWith("rm", StringComparison.CurrentCultureIgnoreCase)) {
                            rmargin = value;
                        } else if (a.StartsWith("m", StringComparison.CurrentCultureIgnoreCase)) {
                            margin = value;
                        }

                    } else if (a.Equals("config", StringComparison.CurrentCultureIgnoreCase)) {
                        writeToConfig = true;
                    } else if (a.Equals("!config", StringComparison.CurrentCultureIgnoreCase)) {
                        writeToConfig = false;

                    } else if (a.Equals("edit", StringComparison.CurrentCultureIgnoreCase)) {
                        LaunchUrl("notepad.exe", file);
//.........这里部分代码省略.........
开发者ID:kodybrown,项目名称:reloc,代码行数:101,代码来源:reloc.cs


注:本文中的Settings.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。