GetDecoder() public method

public GetDecoder ( ) : System.Text.Decoder
return System.Text.Decoder
示例#1
0
    private void GetPrefKeysWindows()
    {
        var charEncoding = new System.Text.ASCIIEncoding();
        var decoder      = charEncoding.GetDecoder();
        // Unity stores prefs in the registry on Windows.

        string regKey = @"Software\" + PlayerSettings.companyName + @"\" + PlayerSettings.productName;

        Debug.Log(regKey);


        RegistryKey key = Registry.CurrentUser.OpenSubKey(regKey);

        foreach (string subkeyName in key.GetValueNames())
        {
            string keyName = subkeyName.Substring(0, subkeyName.LastIndexOf("_"));
            var    val     = key.GetValue(subkeyName);
            string sval    = val.ToString();

            if (!PlayerPrefs.HasKey(keyName))
            {
                Debug.LogWarning(keyName + " " + PlayerPrefs.HasKey(keyName));
            }
            else
            {
                Debug.Log(keyName + " " + PlayerPrefs.HasKey(keyName));
            }

            if (!PlayerPrefs.HasKey(keyName))
            {
                continue;
            }

            // getting the type of the key is not supported in Mono with registry yet :(
            // Have to infer type and guess...
            int    testInt    = -1;
            string newType    = "";
            bool   couldBeInt = int.TryParse(sval, out testInt);

            if (!float.IsNaN(PlayerPrefs.GetFloat(keyName, float.NaN)))
            {
                val     = PlayerPrefs.GetFloat(keyName).ToString();
                newType = "real";
            }
            else if (couldBeInt && (PlayerPrefs.GetInt(keyName, testInt - 10) == testInt))
            {
                newType = "integer";
            }
            else
            {
                newType = "string";
                sval    = System.Text.Encoding.Default.GetString((Byte[])val);
            }

            PlayerPrefStore pref = new PlayerPrefStore(keyName, newType, sval);
            playerPrefs.Add(pref);
        }
    }
 static public int GetDecoder(IntPtr l)
 {
     try {
         System.Text.ASCIIEncoding self = (System.Text.ASCIIEncoding)checkSelf(l);
         var ret = self.GetDecoder();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
示例#3
0
        public string base64Decode(string data)
        {
            try
            {
                System.Text.Encoding encoder = null;
                switch (m_Format)
                {
                    case Formats.UNICODE:
                        encoder = new System.Text.UnicodeEncoding(); break;
                    case Formats.UTF7:
                        encoder = new System.Text.UTF7Encoding(); break;
                    case Formats.UTF8:
                        encoder = new System.Text.UTF8Encoding(); break;
                    case Formats.UTF32:
                        encoder = new System.Text.UTF32Encoding(); break;
                    case Formats.ASCII:
                    default:
                        encoder = new System.Text.ASCIIEncoding(); break;
                }
                System.Text.Decoder decoder = encoder.GetDecoder();
                // System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                // System.Text.Decoder utf8Decode = encoder.GetDecoder();

                byte[] todecode_byte = Convert.FromBase64String(data);
                int charCount = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                char[] decoded_char = new char[charCount];
                decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                string result = new String(decoded_char);
                return result;
            }
            catch (Exception e)
            {
                throw new Exception("Error in base64Decode: " + e.Message);
            }
        }
示例#4
0
            public string getTypeface()
            {
                char [] charBuf = new char[16];

                ASCIIEncoding ae = new ASCIIEncoding();
                Decoder d = ae.GetDecoder();

                d.GetChars( m_Typeface, 0, 6, charBuf, 0 );

                return new string( charBuf );
            }
示例#5
0
            public string getFileName()
            {
                char [] charBuf = new char[6];

                ASCIIEncoding ae = new ASCIIEncoding();
                Decoder d = ae.GetDecoder();

                d.GetChars( m_FileName, 0, 6, charBuf, 0 );

                return new string( charBuf );
            }
示例#6
0
            public string getCharacterComplement()
            {
                char [] charBuf = new char[8];

                ASCIIEncoding ae = new ASCIIEncoding();
                Decoder d = ae.GetDecoder();

                d.GetChars( m_CharacterComplement, 0, 8, charBuf, 0 );

                return new string( charBuf );
            }