Beispiel #1
0
        private void GetCodePage(byte[] buffer, int index, int endDelimiter)
        {
            if (BatchMode)
            {
                _codePage = -2;
                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;
            }
        }
 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);
     }
 }