Beispiel #1
0
        private void buttonTest_Click(object sender, EventArgs e)
        {
            IEncConverter aEC = InitializeEncConverter;

            if (aEC != null)
            {
                try
                {
                    aEC.DirectionForward = !checkBoxTestReverse.Checked;
                    ecTextBoxOutput.Text = aEC.Convert(ecTextBoxInput.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("Test failed! Reason: {0}", ex.Message),
                                    EncConverters.cstrCaption);
                }

                NormConversionType eType = (checkBoxTestReverse.Checked)
                                        ? EncConverter.NormalizeLhsConversionType(ConversionType) : EncConverter.NormalizeRhsConversionType(ConversionType);

                if (eType == NormConversionType.eLegacy)
                {
                    UpdateLegacyCodes(ecTextBoxOutput.Text, m_aEC.CodePageOutput, richTextBoxHexOutput);
                }
                else
                {
                    UpdateUniCodes(ecTextBoxOutput.Text, richTextBoxHexOutput);
                }
            }
        }
Beispiel #2
0
 protected bool IsLhsLegacy(IEncConverter aEC)
 {
     if (aEC.DirectionForward)
     {
         return(EncConverter.NormalizeLhsConversionType(aEC.ConversionType) == NormConversionType.eLegacy);
     }
     else
     {
         return(EncConverter.NormalizeRhsConversionType(aEC.ConversionType) == NormConversionType.eLegacy);
     }
 }
Beispiel #3
0
        public override void Initialize(string converterName, string converterSpec,
                                        ref string lhsEncodingID, ref string rhsEncodingID, ref ConvType conversionType,
                                        ref Int32 processTypeFlags, Int32 codePageInput, Int32 codePageOutput, bool bAdding)
        {
            base.Initialize(converterName, converterSpec, ref lhsEncodingID, ref rhsEncodingID, ref conversionType, ref processTypeFlags, codePageInput, codePageOutput, bAdding);

            m_bLegacy = (EncConverter.NormalizeLhsConversionType(conversionType) == NormConversionType.eLegacy);

            // get the filespec to the project file and the knowledge base
            //  (the KB path *is* the converter spec)
            m_strKnowledgeBaseFileSpec = converterSpec;
            string strProjectFolder = Path.GetDirectoryName(converterSpec);

            m_strProjectFileSpec = String.Format(@"{0}\{1}", strProjectFolder, cstrAdaptItProjectFilename);

            if (bAdding)
            {
                // if we're supposedly adding this one, then clobber our copy of its last modified
                // (there was a problem with us instantiating lots of these things in a row and
                //  not detecting the change because the modified date was within a second of each
                //  other)
                m_timeModifiedKB = m_timeModifiedProj = DateTime.MinValue;
            }
        }
Beispiel #4
0
        protected void TestTabInputChanged()
        {
            if (m_aEC == null)              // means it hasn't been set up yet.
            {
                return;
            }

            if (ecTextBoxInput.TextLength > 0)
            {
                buttonTest.Enabled = true;

                NormConversionType eType = (checkBoxTestReverse.Checked)
                                        ? EncConverter.NormalizeRhsConversionType(ConversionType) : EncConverter.NormalizeLhsConversionType(ConversionType);

                if (eType == NormConversionType.eLegacy)
                {
                    UpdateLegacyCodes(ecTextBoxInput.Text, m_aEC.CodePageInput, richTextBoxHexInput);
                }
                else
                {
                    UpdateUniCodes(ecTextBoxInput.Text, richTextBoxHexInput);
                }
            }
            else
            {
                richTextBoxHexInput.Clear();
                buttonTest.Enabled = false;
            }

            // whenever the input changes, clear out the output
            ecTextBoxOutput.Text      = null;
            richTextBoxHexOutput.Text = null;
        }
Beispiel #5
0
        protected override unsafe void DoConvert
        (
            byte *lpInBuffer,
            int nInLen,
            byte *lpOutBuffer,
            ref int rnOutLen
        )
        {
            rnOutLen = 0;
            if (!String.IsNullOrEmpty(WorkingDir))
            {
                // we need to put it *back* into a string because the StreamWriter that will
                // ultimately write to the StandardInput uses a string. Use the correct codepg.
                byte [] baDst = new byte [nInLen];
                ECNormalizeData.ByteStarToByteArr(lpInBuffer, nInLen, baDst);
                Encoding enc;
                try
                {
                    enc = Encoding.GetEncoding(this.CodePageInput);
                }
                catch
                {
                    enc = Encoding.GetEncoding(EncConverters.cnIso8859_1CodePage);
                }
                string strInput = enc.GetString(baDst);

                // call the helper that calls the exe
                string strOutput = DoExeCall(strInput);

                // if there's a response...
                if (!String.IsNullOrEmpty(strOutput))
                {
                    // ... put it in the output buffer
                    // if the output is legacy, then we need to shrink it from wide to narrow
                    // it'll be legacy either if (the direction is forward and the rhs=eLegacy)
                    // or if (the direction is reverse and the rhs=eLegacy)
                    bool bLegacyOutput =
                        (
                            ((this.DirectionForward == true) &&
                             (EncConverter.NormalizeRhsConversionType(this.ConversionType) == NormConversionType.eLegacy)
                            ) ||
                            ((this.DirectionForward == false) &&
                             (EncConverter.NormalizeLhsConversionType(this.ConversionType) == NormConversionType.eLegacy)
                            )
                        );

                    if (bLegacyOutput)
                    {
                        try
                        {
                            enc = Encoding.GetEncoding(this.CodePageOutput);
                        }
                        catch
                        {
                            enc = Encoding.GetEncoding(EncConverters.cnIso8859_1CodePage);
                        }
                        byte [] baOut = enc.GetBytes(strOutput);
                        ECNormalizeData.ByteArrToByteStar(baOut, lpOutBuffer);
                        rnOutLen = baOut.Length;
                    }
                    else
                    {
                        rnOutLen = strOutput.Length * 2;
                        ECNormalizeData.StringToByteStar(strOutput, lpOutBuffer, rnOutLen);
                    }
                }
            }
            else
            {
                EncConverters.ThrowError(ErrStatus.RegistryCorrupt);
            }
        }