예제 #1
0
 public int GetPacEncoding(byte[] previewBuffer, string fileName)
 {
     using (var pacEncoding = new PacEncoding(previewBuffer, fileName))
     {
         if (pacEncoding.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             Configuration.Settings.General.LastPacCodePage = pacEncoding.CodePageIndex;
             return pacEncoding.CodePageIndex;
         }
         return -2;
     }
 }
예제 #2
0
        private void GetCodePage(byte[] buffer, int index, int endDelimiter)
        {
            if (this.BatchMode)
            {
                if (this._codePage == -1)
                {
                    this._codePage = this.AutoDetectEncoding();
                }

                return;
            }

            byte[] previewBuffer = null;

            if (buffer != null)
            {
                byte[] textSample = new byte[200];
                int textIndex = 0;
                while (index < buffer.Length && buffer[index] != endDelimiter)
                {
                    if (buffer[index] == 0xFF)
                    {
                        if (textIndex < textSample.Length - 1)
                        {
                            textSample[textIndex++] = 32; // ASCII 32 SP (Space)
                        }

                        index++;
                    }
                    else if (buffer[index] == 0xFE)
                    {
                        if (textIndex < textSample.Length - 3)
                        {
                            textSample[textIndex++] = buffer[index];
                            textSample[textIndex++] = buffer[index + 1];
                            textSample[textIndex++] = buffer[index + 2];
                        }

                        index += 3;
                    }
                    else
                    {
                        if (textIndex < textSample.Length - 1)
                        {
                            textSample[textIndex++] = buffer[index];
                        }

                        index++;
                    }
                }

                previewBuffer = new byte[textIndex];
                for (int i = 0; i < textIndex; i++)
                {
                    previewBuffer[i] = textSample[i];
                }
            }

            using (PacEncoding pacEncoding = new PacEncoding(previewBuffer, this._fileName))
            {
                if (pacEncoding.ShowDialog() == DialogResult.OK)
                {
                    this._codePage = pacEncoding.CodePageIndex;
                    Configuration.Settings.General.LastPacCodePage = this._codePage;
                }
                else
                {
                    this._codePage = -2;
                }
            }
        }
예제 #3
0
        private void GetCodePage(byte[] buffer, int index, int endDelimiter)
        {
            if (BatchMode)
            {
                if (_codePage == -1)
                    _codePage = AutoDetectEncoding();
                return;
            }

            byte[] previewBuffer = null;

            if (buffer != null)
            {
                byte[] textSample = new byte[200];
                int textIndex = 0;
                while (index < buffer.Length && buffer[index] != endDelimiter)
                {
                    if (buffer[index] == 0xFF)
                    {
                        textSample[textIndex++] = 32; // space
                    }
                    else if (buffer[index] == 0xFE)
                    {
                        if (textIndex < textSample.Length - 3)
                        {
                            textSample[textIndex++] = buffer[index];
                            textSample[textIndex++] = buffer[index + 1];
                            textSample[textIndex++] = buffer[index + 2];
                        }
                        index += 3;
                    }
                    if (textIndex < textSample.Length - 1)
                        textSample[textIndex++] = buffer[index];
                    index++;
                }
                previewBuffer = new byte[textIndex];
                for (int i = 0; i < textIndex; i++)
                    previewBuffer[i] = textSample[i];
            }

            var pacEncoding = new PacEncoding(previewBuffer, _fileName);
            if (pacEncoding.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _codePage = pacEncoding.CodePageIndex;
                Configuration.Settings.General.LastPacCodePage = _codePage;
            }
            else
            {
                _codePage = -2;
            }
        }