コード例 #1
0
ファイル: Mainform.cs プロジェクト: Timwi/ExpertSokoban
        /// <summary>
        /// Invoked by "Level => Open level file" or the relevant toolbar button.
        /// Allows the user to load a text file containing Sokoban levels.
        /// </summary>
        private void openLevelFile(object sender, EventArgs e)
        {
            if (!mayDestroyEverything(Program.Tr.Mainform_MessageTitle_OpenLevelFile))
            {
                return;
            }

            OpenFileDialog openDlg = new OpenFileDialog();

            openDlg.DefaultExt       = "txt";
            openDlg.Filter           = Program.Tr.Save_FileType_TextFiles + "|*.txt|" + Program.Tr.Save_FileType_AllFiles + "|*.*";
            openDlg.InitialDirectory = Program.Settings.LastOpenSaveDirectory;
            if (openDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                lstLevels.LoadLevelPack(openDlg.FileName);
            }
            catch (LevelListBox.InvalidLevelException)
            {
                DlgMessage.ShowError(Program.Tr.Mainform_InvalidFile, Program.Tr.Mainform_InvalidFile_Title);
                return;
            }

            Program.Settings.LastOpenSaveDirectory = Path.GetDirectoryName(openDlg.FileName);
            Program.Settings.SaveThreaded();
            ctMainArea.Modified = false;
            showLevelList(true);
            lstLevels.PlayFirstUnsolved();
        }
コード例 #2
0
        private void tryItOnline(object sender, EventArgs e)
        {
            if (null == _lastRendering)
            {
                DlgMessage.ShowError("Nothing to run!");
            }
            else
            {
                const string languageId = "hexagony", fieldSeparator = "\xff";

                var stateString = languageId + fieldSeparator + fieldSeparator
                                  + Regex.Replace(_file.Grid.ToString(), "\r\n", "\n")
                                  + fieldSeparator + fieldSeparator;

                byte[] bytes = new byte[stateString.Length];
                for (int i = 0; i < stateString.Length; ++i)
                {
                    bytes[i] = (byte)stateString[i];
                }

                bytes = Ionic.Zlib.ZlibStream.CompressBuffer(bytes);
                byte[] truncatedHeader = new byte[bytes.Length - 2];
                Array.Copy(bytes, 2, truncatedHeader, 0, truncatedHeader.Length);

                System.Diagnostics.Process.Start("https://tio.run/##" + Regex.Replace(
                                                     System.Convert.ToBase64String(truncatedHeader).Replace('+', '@'),
                                                     "=+", ""));
            }
        }
コード例 #3
0
 private void copyHexagonySource(object sender, EventArgs e)
 {
     if (null == _lastRendering)
     {
         DlgMessage.ShowError("Nothing to copy!");
     }
     else
     {
         System.Windows.Forms.Clipboard.SetText(_file.Grid.ToString());
     }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: rstarkov/i4c
 /// <summary>
 /// Creates a new compressor of a specified name. Use to obtain an actual compressor
 /// instance given an algorithm name.
 /// </summary>
 public static Compressor GetCompressor(string name)
 {
     if (Compressors.ContainsKey(name))
     {
         Compressor compr = (Compressor)Compressors[name].GetConstructor(new Type[] { }).Invoke(new object[] { });
         compr.Name = name;
         return(compr);
     }
     else
     {
         DlgMessage.ShowError("Compressor named {0} is not defined".Fmt(name));
         Environment.Exit(1);
         return(null);
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: rstarkov/i4c
        static void Main(string[] args)
        {
            //CodecTests.TestRandom();
            PatternHashTable.SelfTest();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            int worker, dummy;

            ThreadPool.SetMinThreads(Environment.ProcessorCount, 10);
            ThreadPool.SetMaxThreads(Environment.ProcessorCount, 10);
            ThreadPool.GetAvailableThreads(out worker, out dummy);
            System.Diagnostics.Debug.Assert(worker == Environment.ProcessorCount);


            if (args.Length == 0)
            {
                SettingsUtil.LoadSettings(out Settings);
                MainForm form = new MainForm();
                Application.Run(form);
                Settings.Save();
            }
            else if (args[0] == "?")
            {
                DlgMessage.ShowInfo("Usage:\n  i4c.exe - run interactive GUI.\n  i4c.exe <algorithm> <filename> [<arg1> <arg2> ...] - compress/decompress single file.\n  i4c.exe benchmark <algorithm> [<arg1> <arg2> ...] - benchmark on all files in cur dir.\n\nAvailable algorithms:\n\n" + Compressors.Keys.Select(compr => "* " + compr + "\n").JoinString());
            }
            else if (args[0] == "benchmark")
            {
                if (args.Length == 1)
                {
                    DlgMessage.ShowError("Must also specify the name of the algorithm to benchmark");
                    return;
                }
                command_Benchmark(args[1], args.Skip(2).Select(val => (RVariant)val).ToArray());
            }
            else
            {
                if (args.Length < 2)
                {
                    DlgMessage.ShowError("Must specify at least the algorithm name and the file name");
                    return;
                }
                command_Single(args[1], args[0], args.Skip(2).Select(val => (RVariant)val).ToArray());
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: rstarkov/AccountsWeb
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Ut.RunMain(() =>
            {
                SettingsUtil.LoadSettings(out Settings);
                Tr = Lingo.LoadTranslationOrDefault <Translation>("AccountsWeb", ref Settings.Language);

                Interface = new WebInterface();
                TrayForm  = new TrayForm();

                if (Settings.LastFileName != null)
                {
                    OpenFile(Settings.LastFileName);
                }

#if DEBUG
                var defaultTr = new Translation();
                using (var tempConfigForm = new ConfigForm(new GncFileWrapper()))
                    using (var g = new Lingo.TranslationFileGenerator(PathUtil.AppPathCombine("../../users/rs/GnuCash/AccountsWeb/Translation.g.cs")))
                    {
                        g.TranslateControl(TrayForm, defaultTr.TrayForm);
                        g.TranslateControl(TrayForm.TrayMenu, defaultTr.TrayMenu);
                        g.TranslateControl(tempConfigForm, defaultTr.Config);
                    }
#endif

                Application.Run();

                Settings.Save();
            },
                       excp =>
            {
                var message = "\n" + "An internal error has occurred in RunLogged: ";
                foreach (var ex in excp.SelectChain(ex => ex.InnerException))
                {
                    message += "\n" + ex.GetType() + ": " + ex.Message;
                    message += "\n" + ex.StackTrace;
                }
                DlgMessage.ShowError(message);
            });
        }
コード例 #7
0
        static int Main(string[] args)
        {
            // Configure Classify. This goes before the post-build check because it depends on it
            Classify.DefaultOptions = new ClassifyOptions()
                                      .AddTypeOptions(typeof(W.Color), new colorTypeOptions())
                                      .AddTypeOptions(typeof(D.Color), new colorTypeOptions())
                                      .AddTypeOptions(typeof(Filename), new filenameTypeOptions())
                                      .AddTypeOptions(typeof(ObservableCollection <LayerBase>), new listLayerBaseOptions())
                                      .AddTypeOptions(typeof(ObservableCollection <EffectBase>), new listEffectBaseOptions());

            if (args.Length == 2 && args[0] == "--post-build-check")
            {
                return(RT.Util.Ut.RunPostBuildChecks(args[1], Assembly.GetExecutingAssembly()));
            }

            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

#if DEBUG
            CompositePath.Tests();
#endif

            Thread.CurrentThread.Name = "Main";
#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += (_, ea) =>
            {
                bool copy = DlgMessage.ShowError(App.Translation.Error.ExceptionGlobal,
                                                 App.Translation.Error.ErrorToClipboard_Copy, App.Translation.Error.ErrorToClipboard_OK) == 0;
                if (copy)
                {
                    if (Ut.ClipboardSet(Ut.ExceptionToDebugString(ea.ExceptionObject)))
                    {
                        DlgMessage.ShowInfo(App.Translation.Error.ErrorToClipboard_Copied);
                    }
                }
            };
#else
            var dummy  = App.Translation.Error.ExceptionGlobal; // to keep Lingo happy that the string is used
            var dummy2 = new StringBuilder();                   // to keep the "using" clause used
#endif

            // Find all the layer and effect types in the assembly (required before settings are loaded)
            App.LayerTypes  = findTypes <LayerBase>("layer");
            App.EffectTypes = findTypes <EffectBase>("effect");

            // Load all settings
            SettingsUtil.LoadSettings(out App.Settings);
            UpdateSettingsIfNecessary();

            // Guess the language if the OS language has changed (or this is the first run)
            var osLingo = Ut.GetOsLanguage();
            if (App.Settings.OsLingo != osLingo)
            {
                App.Settings.OsLingo = App.Settings.Lingo = osLingo;
            }
            // Load translation
            App.Translation = Lingo.LoadTranslationOrDefault <Translation>("TankIconMaker", ref App.Settings.Lingo);

            // Run the UI
            var app = new App();
            app.InitializeComponent();
            app.Run();

            // Save settings upon exit, even though they should be saved on every change anyway
            App.Settings.SaveQuiet();

            return(0);
        }