コード例 #1
0
        public bool Prompt <T>(string message, out T result, params string[] skipCmds)
        {
            Print.Line(message);
            string line = Console.ReadLine();

            result = default;

            if (skipCmds.Contains(line))
            {
                return(false);
            }

            #region integers
            if (typeof(T) == typeof(short))
            {
                if (!short.TryParse(line, out short s))
                {
                    if (!int.TryParse(line, out int i))
                    {
                        if (!long.TryParse(line, out long l))
                        {
                            PromptInvalidValueEntered?.Invoke(this, EventArgs.Empty);
                            return(Prompt <T>(message, out result, skipCmds));
                        }
                        result = (T)(object)(short)l;
                    }
                    result = (T)(object)(short)i;
                }
                result = (T)(object)s;
            }
            else if (typeof(T) == typeof(int))
            {
                if (!short.TryParse(line, out short s))
                {
                    if (!int.TryParse(line, out int i))
                    {
                        if (!long.TryParse(line, out long l))
                        {
                            PromptInvalidValueEntered?.Invoke(this, EventArgs.Empty);
                            return(Prompt <T>(message, out result, skipCmds));
                        }
                        result = (T)(object)(int)l;
                    }
                    result = (T)(object)i;
                }
                result = (T)(object)(int)s;
            }
            else if (typeof(T) == typeof(long))
            {
                if (!short.TryParse(line, out short s))
                {
                    if (!int.TryParse(line, out int i))
                    {
                        if (!long.TryParse(line, out long l))
                        {
                            PromptInvalidValueEntered?.Invoke(this, EventArgs.Empty);
                            return(Prompt <T>(message, out result, skipCmds));
                        }
                        result = (T)(object)l;
                    }
                    result = (T)(object)(long)i;
                }
                result = (T)(object)(long)s;
            }
            #endregion

            #region floats
            else if (typeof(T) == typeof(float))
            {
                if (!float.TryParse(line, out float f))
                {
                    if (!double.TryParse(line, out double d))
                    {
                        PromptInvalidValueEntered?.Invoke(this, EventArgs.Empty);
                        return(Prompt <T>(message, out result, skipCmds));
                    }
                    result = (T)(object)(float)d;
                }
                result = (T)(object)f;
            }
            else if (typeof(T) == typeof(double))
            {
                if (!float.TryParse(line, out float f))
                {
                    if (!double.TryParse(line, out double d))
                    {
                        PromptInvalidValueEntered?.Invoke(this, EventArgs.Empty);
                        return(Prompt <T>(message, out result, skipCmds));
                    }
                    result = (T)(object)d;
                }
                result = (T)(object)(double)f;
            }
            #endregion

            else if (typeof(T) == typeof(string))
            {
                result = (T)(object)line;
            }

            if (result == null)
            {
                PromptInvalidValueEntered?.Invoke(this, EventArgs.Empty);
                return(Prompt <T>(message, out result, skipCmds));
            }
            else
            {
                PromptSuccess?.Invoke(this, EventArgs.Empty);
                return(true);
            }
        }
コード例 #2
0
        public void SaveResultToDisk(bool exportReconstruction = true, bool exportVarianceTest = true, string targetDir = null, string name = null)
        {
            name ??= Config.Name;
            targetDir ??= Config.TargetDir;
            if (State.Config.Verbose)
            {
                Print.Line(ConsoleColor.Magenta, "Starting to batch save to: " + targetDir);
            }

            string path = Path.Combine(targetDir, name);

            if (Directory.Exists(path))
            {
                string[] files = Directory.GetFiles(path);

                foreach (string filePath in files)
                {
                    File.Delete(filePath);
                }
            }
            Directory.CreateDirectory(path);

            for (int x = 0; x < Result.GetLength(0); x++)
            {
                for (int y = 0; y < Result.GetLength(1); y++)
                {
                    ChunkData chunk     = Result[x, y];
                    string    finalPath = Path.Combine(path, name + "-" + chunk.X + "-" + chunk.Y + ".png");

                    if (!Config.CompatibilityMode)
                    {
                        Thread thread = new Thread(() =>
                                                   chunk.Bitmap.Save(finalPath, ImageFormat.Png)
                                                   );
                        thread.Start();
                    }
                    else
                    {
                        chunk.Bitmap.Save(finalPath, ImageFormat.Png);
                    }

                    if (State.Config.Verbose)
                    {
                        Print.Line(ConsoleColor.Green, "Saved a file to: " + finalPath);
                    }
                }
            }

            if (exportReconstruction)
            {
                //Reconstructor reconstructor = new Reconstructor(Result, name, (short)OriginalBitmap.Width, (short)OriginalBitmap.Height);
                Reconstructor reconstructor = new Reconstructor(path, name, (short)OriginalBitmap.Width, (short)OriginalBitmap.Height);
                if (exportVarianceTest)
                {
                    reconstructor.ReconstructAndCompare(OriginalBitmap, path, Config.CompatibilityMode);
                }
                else
                {
                    reconstructor.Reconstruct(targetDir);
                }
            }
        }