protected bool checkPageIndex(out string msg, int page, int max)
        {
            string @string = ErrorMsg.GetString(ErrorMsg.DEFINES.OVER_PAGE_INDEX);

            ErrorMsg.GetString(ErrorMsg.DEFINES.LESS_PAGE_INDEX);
            bool   flag  = true;
            bool   flag2 = true;
            string msg2  = string.Empty;
            string empty = string.Empty;

            msg  = string.Empty;
            flag = checkOver(out msg2, @string, "(page)", page, max);
            bool result = true;

            if (!flag2)
            {
                result = false;
                msg   += empty;
            }
            if (!flag)
            {
                result = false;
                msg   += msg2;
            }
            return(result);
        }
        protected bool checkPixelFormat_8bppIndexed(out string msg, string filepath)
        {
            msg = string.Empty;
            bool flag = true;

            try
            {
                BinaryReader binaryReader = new BinaryReader(File.OpenRead(filepath));
                byte[]       array        = new byte[32];
                binaryReader.Read(array, 0, 32);
                if (3 != array[25])
                {
                    flag = false;
                }
            }
            catch
            {
                flag = false;
            }
            if (!flag)
            {
                msg  = msg + ErrorMsg.GetString(ErrorMsg.DEFINES.NOT_INDEX_COLOR256) + "\n";
                msg += "\n";
            }
            return(flag);
        }
        protected bool checkHeight(out string msg, int h, int max)
        {
            string @string = ErrorMsg.GetString(ErrorMsg.DEFINES.OVER_IMAGE_HEIGHT);
            bool   result  = checkValue(out msg, @string, "(pixel)", h, max);

            msg += "\n";
            return(result);
        }
        protected bool checkWidth(out string msg, int w, int max)
        {
            string @string = ErrorMsg.GetString(ErrorMsg.DEFINES.OVER_IMAGE_WIDTH);
            bool   result  = checkValue(out msg, @string, "(pixel)", w, max);

            msg += "\n";
            return(result);
        }
        protected bool checkStringNullOrEmpty(out string msg, string str)
        {
            msg = string.Empty;
            bool result = true;

            if (string.IsNullOrEmpty(str))
            {
                msg    = ErrorMsg.GetString(ErrorMsg.DEFINES.EMPTY_STRING);
                msg   += "\n";
                result = false;
            }
            return(result);
        }
        protected bool checkFileSize(out string msg, string filepath, long max_byte)
        {
            msg = string.Empty;
            if (max_byte <= 0)
            {
                return(true);
            }
            char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
            if (0 < Path.GetFileNameWithoutExtension(filepath).IndexOfAny(invalidFileNameChars))
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.INVALID_CHARS_IN_FILEPATH);
                msg += "\n";
                return(false);
            }
            if (!StrictCheckFileName_VITA(filepath))
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.INVALID_CHARS_IN_FILEPATH);
                msg += "\n";
                return(false);
            }
            FileInfo fileInfo = new FileInfo(filepath);
            bool     flag;

            if (fileInfo != null)
            {
                long   value_unit = 1L;
                string post_msg   = "(byte)";
                if (1048576 <= fileInfo.Length && 1048576 <= max_byte)
                {
                    value_unit = 1048576L;
                    post_msg   = "(MiB)";
                }
                else if (1024 <= fileInfo.Length && 1024 <= max_byte)
                {
                    value_unit = 1024L;
                    post_msg   = "(KiB)";
                }
                string @string = ErrorMsg.GetString(ErrorMsg.DEFINES.OVER_FILE_SIZE);
                flag = checkOver(out msg, @string, post_msg, fileInfo.Length, max_byte, value_unit);
                if (!flag)
                {
                    msg += "\n";
                }
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
        protected bool checkStringLength(out string msg, string str, int max_length)
        {
            msg = string.Empty;
            bool result = true;

            if (max_length < str.Length)
            {
                msg  = str + "\n";
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.OVER_PATH_LENGTH);
                string text = msg;
                msg    = text + str.Length + "/" + max_length + "(chars)\n";
                result = false;
            }
            return(result);
        }
Beispiel #8
0
        private static void exec(string arg, bool blocking, out string output)
        {
            m_error_msg = string.Empty;
            output      = string.Empty;
            MainForm.m_mainForm.Disable_menuItemDevkit();
            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.FileName                = "psp2ctrl.exe";
            processStartInfo.Arguments               = arg;
            processStartInfo.CreateNoWindow          = true;
            processStartInfo.UseShellExecute         = false;
            processStartInfo.ErrorDialog             = true;
            processStartInfo.ErrorDialogParentHandle = MainForm.m_mainForm.Handle;
            processStartInfo.RedirectStandardOutput  = true;
            processStartInfo.RedirectStandardError   = true;
            Process process = null;

            try
            {
                process = Process.Start(processStartInfo);
                process.OutputDataReceived += processDataReceived2;
                process.ErrorDataReceived  += processDataReceived;
                if (blocking)
                {
                    output = process.StandardOutput.ReadToEnd();
                    return;
                }
                process.SynchronizingObject = MainForm.m_mainForm;
                process.EnableRaisingEvents = true;
                process.Exited += exited;
            }
            catch (FileNotFoundException)
            {
                m_error_msg = ErrorMsg.GetString(ErrorMsg.DEFINES.CAN_NOT_BOOT) + " : psp2ctrl.exe\n\n" + ErrorMsg.GetString(ErrorMsg.DEFINES.CHECK_TM_PATH_OR_INSRALLED) + m_error_msg;
                exited(process, new EventArgs());
            }
            catch (Win32Exception)
            {
                m_error_msg = ErrorMsg.GetString(ErrorMsg.DEFINES.CAN_NOT_BOOT) + " : psp2ctrl.exe\n\n" + ErrorMsg.GetString(ErrorMsg.DEFINES.CHECK_TM_PATH_OR_INSRALLED) + m_error_msg;
                exited(process, new EventArgs());
            }
            catch (Exception ex3)
            {
                m_error_msg += ex3.Message;
                exited(process, new EventArgs());
            }
        }
        protected bool checkStringByteSize(out string msg, string str, int max_bytes)
        {
            msg = string.Empty;
            bool     result    = true;
            Encoding encoding  = Encoding.GetEncoding("utf-8");
            int      byteCount = encoding.GetByteCount(str);

            if (max_bytes < byteCount)
            {
                msg  = "\"" + str + "\"\n";
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.OVER_STRING_BYTE_SIZE);
                string text = msg;
                msg    = text + byteCount + "/" + max_bytes + "(byte)\n";
                result = false;
            }
            return(result);
        }
        protected bool checkImageFile(out string msg, string filepath, int max_filepath_length, bool null_error_filepath, int max_w, int max_h, long max_file_size)
        {
            bool result = true;

            msg = string.Empty;
            if (string.IsNullOrEmpty(filepath))
            {
                if (null_error_filepath)
                {
                    msg   += ErrorMsg.GetString(ErrorMsg.DEFINES.EMPTY_STRING);
                    msg   += "\n";
                    result = false;
                }
                return(result);
            }
            string extension = Path.GetExtension(filepath);

            if (string.IsNullOrEmpty(extension))
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.INVALID_FILE_PATH);
                msg += "\n";
                return(false);
            }
            if (extension.ToLower() != ".png")
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.NOT_PNG_FILE);
                msg += "\n";
                return(false);
            }
            char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
            if (0 < Path.GetFileNameWithoutExtension(filepath).IndexOfAny(invalidFileNameChars))
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.INVALID_CHARS_IN_FILEPATH);
                msg += "\n";
                return(false);
            }
            if (!StrictCheckFileName_VITA(filepath))
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.INVALID_CHARS_IN_FILEPATH);
                msg += "\n";
                return(false);
            }
            if (!File.Exists(filepath))
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.NOT_FOUND_FILE);
                msg += "\n";
                return(false);
            }
            Image image = null;

            try
            {
                image = Image.FromFile(filepath);
            }
            catch (FileNotFoundException)
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.NOT_FOUND_FILE);
                msg += "\n";
                return(false);
            }
            catch (OutOfMemoryException)
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.NOT_PNG_FILE);
                msg += "\n";
                return(false);
            }
            catch (ArgumentException)
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.READ_FILE_FAILURE);
                msg += "\n";
                return(false);
            }
            catch (Exception)
            {
                image = null;
            }
            if (!ImageFormat.Png.Equals(image.RawFormat))
            {
                result = false;
                msg   += ErrorMsg.GetString(ErrorMsg.DEFINES.NOT_PNG_FILE);
                msg   += "\n";
            }
            if (image == null)
            {
                msg += ErrorMsg.GetString(ErrorMsg.DEFINES.READ_FILE_FAILURE);
                msg += "\n";
                return(false);
            }
            string msg2;

            if (!checkFileSize(out msg2, filepath, max_file_size))
            {
                result = false;
                msg   += msg2;
            }
            if (!checkWidth(out msg2, image.Width, max_w))
            {
                result = false;
                msg   += msg2;
            }
            if (!checkHeight(out msg2, image.Height, max_h))
            {
                result = false;
                msg   += msg2;
            }
            if (!checkPixelFormat_8bppIndexed(out msg2, filepath))
            {
                result = false;
                msg   += msg2;
            }
            return(result);
        }