Exemplo n.º 1
0
        // Token: 0x06000487 RID: 1159 RVA: 0x00017358 File Offset: 0x00015558
        public void LoadDictionary(string path)
        {
            bool flag = global::System.IO.File.Exists(path);

            if (flag)
            {
                using (global::System.IO.StreamReader streamReader = new global::System.IO.StreamReader(global::System.IO.File.OpenRead(path), global::System.Text.Encoding.UTF8))
                {
                    global::VRGIN.Controls.Speech.VoiceCommand voiceCommand = null;
                    while (!streamReader.EndOfStream)
                    {
                        string text  = streamReader.ReadLine().Trim().ToLowerInvariant();
                        bool   flag2 = global::VRGIN.Controls.Speech.DictionaryReader.IsCommand(text);
                        if (flag2)
                        {
                            bool flag3 = this._Dictionary.TryGetValue(global::VRGIN.Controls.Speech.DictionaryReader.ExtractCommand(text), ref voiceCommand);
                            if (flag3)
                            {
                                voiceCommand.Texts.Clear();
                            }
                        }
                        else
                        {
                            bool flag4 = voiceCommand != null && text.Length > 0;
                            if (flag4)
                            {
                                voiceCommand.Texts.Add(text);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// 通过密钥,对字符串形式的加密数据进行解密
 /// </summary>
 /// <param name="bytes"></param>
 /// <param name="SecretKey">密钥</param>
 /// <param name="SingleLine">True:解析单行;False:解析所有</param>
 /// <param name="Standard">是否使用标准方式</param>
 /// <returns></returns>
 public static string Decrypt(this byte[] bytes, string SecretKey, bool SingleLine = true, bool Standard = false)
 {
     DESCryptoServiceProvider des = new DESCryptoServiceProvider();
     if (Standard)
     {
         des.Mode = CipherMode.ECB;
         des.Padding = PaddingMode.Zeros;
     }
     des.Key = SecretKey.ToMD5().Substring(0, 0x08).ToBytes();
     des.IV = SecretKey.ToMD5().Substring(0, 0x08).ToBytes();
     global::System.IO.MemoryStream ms = new global::System.IO.MemoryStream(bytes);
     string val = string.Empty;
     try
     {
         CryptoStream encStream = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Read);
         global::System.IO.StreamReader sr = new global::System.IO.StreamReader(encStream);
         val = SingleLine ? sr.ReadLine() : sr.ReadToEnd();
         sr.Close();
         encStream.Close();
     }
     catch
     {
         val = "密钥错误,解密失败。";
     }
     finally
     {
         ms.Close();
     }
     return val;
 }
        public async Task <string> SerializeMarshallAsync <T>(T t)
        {
            // if you can, only create one serializer
            // creating serializers is an expensive
            // operation and can be slow
            global::System.Xml.Serialization.XmlSerializer serializer = null;

            serializer = new global::System.Xml.Serialization.XmlSerializer(typeof(T));

            // we will write the our result to memory
            //await using
            global::System.IO.MemoryStream stream = new global::System.IO.MemoryStream();
            // the string will be utf8 encoded
            //await using
            global::System.IO.StreamWriter writer = new global::System.IO.StreamWriter
                                                    (
                stream,
                global::System.Text.Encoding.UTF8
                                                    );

            // here we go!
            serializer.Serialize(writer, t);

            // flush our write to make sure its all there
            await writer.FlushAsync();

            // reset the stream back to 0
            stream.Position = 0;

            using global::System.IO.StreamReader reader = new global::System.IO.StreamReader(stream);

            string xml = await reader.ReadToEndAsync();

            return(xml);
        }
Exemplo n.º 4
0
        public async Task <string> SerializeMarshallAsync <T>(T t)
        {
            global::System.IO.MemoryStream stream = new global::System.IO.MemoryStream();
            await global::System.Text.Json.JsonSerializer.SerializeAsync(stream, t);

            // reset the stream back to 0
            stream.Position = 0;

            using global::System.IO.StreamReader reader = new global::System.IO.StreamReader(stream);

            // we reread the stream to a string
            string json = await reader.ReadToEndAsync();

            return(json);
        }
Exemplo n.º 5
0
        public void Close()
        {
            if (tr != null)
            {
                tr.Close();
            }

            if (tw != null)
            {
                tw.Close();
            }

            tr = null;
            tw = null;
        }
Exemplo n.º 6
0
        protected virtual async System.Threading.Tasks.Task <ObjectResponseResult <T> > ReadObjectResponseAsync <T>(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary <string, System.Collections.Generic.IEnumerable <string> > headers)
        {
            if (response == null || response.Content == null)
            {
                return(new ObjectResponseResult <T>(default(T), string.Empty));
            }

            if (ReadResponseAsString)
            {
                var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                try
                {
                    var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(responseText, JsonSerializerSettings);
                    return(new ObjectResponseResult <T>(typedBody, responseText));
                }
                catch (Newtonsoft.Json.JsonException exception)
                {
                    var message = "Could not deserialize the response body string as " + typeof(T).FullName + ".";
                    throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception);
                }
            }
            else
            {
                try
                {
                    using (var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                        using (var streamReader = new System.IO.StreamReader(responseStream))
                            using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader))
                            {
                                var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings);
                                var typedBody  = serializer.Deserialize <T>(jsonTextReader);
                                return(new ObjectResponseResult <T>(typedBody, string.Empty));
                            }
                }
                catch (Newtonsoft.Json.JsonException exception)
                {
                    var message = "Could not deserialize the response body stream as " + typeof(T).FullName + ".";
                    throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception);
                }
            }
        }
        public async Task <string> SerializeMarshallAsync <T>(T t)
        {
            string result = null;

            using (global::System.IO.MemoryStream ms = new global::System.IO.MemoryStream())
            {
                global::System.Runtime.Serialization.DataContractSerializer serializer = null;
                serializer = new global::System.Runtime.Serialization.DataContractSerializer(typeof(T));

                serializer.WriteObject(ms, t);

                ms.Seek(0, global::System.IO.SeekOrigin.Begin);

                using (global::System.IO.StreamReader sr = new global::System.IO.StreamReader(ms))
                {
                    result = await sr.ReadToEndAsync();
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        public ConfigTextStream(string name)
        {
            if (name == "")
            {
                return;
            }

            _path = SystemVariables.MyApplicationConfigPath + @"/" + name + ".config";
            GetIDs();
            try
            {
                FileInfo fi = new FileInfo(_path);
                if (fi.Exists)
                {
                    tr = new global::System.IO.StreamReader(_path);
                }
            }
            catch
            {
                Close();
            }
        }
Exemplo n.º 9
0
 public ConfigTextStream(string name, bool write, bool append)
 {
     try
     {
         _path = SystemVariables.MyApplicationConfigPath + @"/" + name + ".config";
         GetIDs();
         if (!write)
         {
             FileInfo fi = new FileInfo(_path);
             if (fi.Exists)
             {
                 tr = new global::System.IO.StreamReader(_path);
             }
         }
         else
         {
             tw = new global::System.IO.StreamWriter(_path, append);
         }
     }
     catch/*(Exception ex)*/
     {
         Close();
     }
 }
Exemplo n.º 10
0
        // Internal Helper Functions
        internal static FMODPlatform GetCurrentPlatform()
        {
#if UNITY_EDITOR
            return(FMODPlatform.PlayInEditor);
#elif UNITY_STANDALONE_WIN
            return(FMODPlatform.Windows);
#elif UNITY_STANDALONE_OSX
            return(FMODPlatform.Mac);
#elif UNITY_STANDALONE_LINUX
            return(FMODPlatform.Linux);
#elif UNITY_TVOS
            return(FMODPlatform.AppleTV);
#elif UNITY_IOS
            FMODPlatform result;
            switch (UnityEngine.iOS.Device.generation)
            {
            case UnityEngine.iOS.DeviceGeneration.iPhone5:
            case UnityEngine.iOS.DeviceGeneration.iPhone5C:
            case UnityEngine.iOS.DeviceGeneration.iPhone5S:
            case UnityEngine.iOS.DeviceGeneration.iPadAir1:
            case UnityEngine.iOS.DeviceGeneration.iPadMini2Gen:
            case UnityEngine.iOS.DeviceGeneration.iPhone6:
            case UnityEngine.iOS.DeviceGeneration.iPhone6Plus:
            case UnityEngine.iOS.DeviceGeneration.iPadMini3Gen:
            case UnityEngine.iOS.DeviceGeneration.iPadAir2:
                result = FMODPlatform.MobileHigh;
                break;

            default:
                result = FMODPlatform.MobileLow;
                break;
            }

            UnityEngine.Debug.Log(String.Format("FMOD Studio: Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
            return(result);
#elif UNITY_ANDROID
            FMODPlatform result;
            if (SystemInfo.processorCount <= 2)
            {
                result = FMODPlatform.MobileLow;
            }
            else if (SystemInfo.processorCount >= 8)
            {
                result = FMODPlatform.MobileHigh;
            }
            else
            {
                // check the clock rate on quad core systems
                string freqinfo = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
                using (global::System.IO.TextReader reader = new global::System.IO.StreamReader(freqinfo))
                {
                    try
                    {
                        string line = reader.ReadLine();
                        int    khz  = Int32.Parse(line) / 1000;
                        if (khz >= 1600)
                        {
                            result = FMODPlatform.MobileHigh;
                        }
                        else
                        {
                            result = FMODPlatform.MobileLow;
                        }
                    }
                    catch
                    {
                        // Assume worst case
                        result = FMODPlatform.MobileLow;
                    }
                }
            }

            UnityEngine.Debug.Log(String.Format("FMOD Studio: Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
            return(result);
#elif UNITY_WINRT_8_1
            FMODPlatform result;
            if (SystemInfo.processorCount <= 2)
            {
                result = FMODPlatform.MobileLow;
            }
            else
            {
                result = FMODPlatform.MobileHigh;
            }

            UnityEngine.Debug.Log(String.Format("FMOD Studio: Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
            return(result);
#elif UNITY_PS4
            return(FMODPlatform.PS4);
#elif UNITY_XBOXONE
            return(FMODPlatform.XboxOne);
#elif UNITY_PSP2
            return(FMODPlatform.PSVita);
#elif UNITY_WIIU
            return(FMODPlatform.WiiU);
#elif UNITY_WSA_10_0
            return(FMODPlatform.UWP);
#endif
        }
Exemplo n.º 11
0
        // Internal Helper Functions
        internal static FMODPlatform GetCurrentPlatform()
        {
            #if UNITY_EDITOR
            return FMODPlatform.PlayInEditor;
            #elif UNITY_STANDALONE_WIN
            return FMODPlatform.Windows;
            #elif UNITY_STANDALONE_OSX
            return FMODPlatform.Mac;
            #elif UNITY_STANDALONE_LINUX
            return FMODPlatform.Linux;
			#elif UNITY_TVOS
			return FMODPlatform.AppleTV;
            #elif UNITY_IOS
            FMODPlatform result;
            switch (UnityEngine.iOS.Device.generation)
            {
			case UnityEngine.iOS.DeviceGeneration.iPhone5:
			case UnityEngine.iOS.DeviceGeneration.iPhone5C:
			case UnityEngine.iOS.DeviceGeneration.iPhone5S:
			case UnityEngine.iOS.DeviceGeneration.iPadAir1:
			case UnityEngine.iOS.DeviceGeneration.iPadMini2Gen:
			case UnityEngine.iOS.DeviceGeneration.iPhone6:
			case UnityEngine.iOS.DeviceGeneration.iPhone6Plus:
			case UnityEngine.iOS.DeviceGeneration.iPadMini3Gen:
			case UnityEngine.iOS.DeviceGeneration.iPadAir2:
                result = FMODPlatform.MobileHigh;
				break;
            default:
                result = FMODPlatform.MobileLow;
				break;
            }

            UnityEngine.Debug.Log(String.Format("FMOD Studio: Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
            return result;
            #elif UNITY_ANDROID
            FMODPlatform result;
            if (SystemInfo.processorCount <= 2)
            {
                result = FMODPlatform.MobileLow;
            }
            else if (SystemInfo.processorCount >= 8)
            {
                result = FMODPlatform.MobileHigh;
            }
            else
            {
                // check the clock rate on quad core systems            
                string freqinfo = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
                using(global::System.IO.TextReader reader = new global::System.IO.StreamReader(freqinfo))
                {
                    try
                    {
                        string line = reader.ReadLine();
                        int khz = Int32.Parse(line) / 1000;
                        if (khz >= 1600)
                        {
                            result = FMODPlatform.MobileHigh;
                        }
                        else
                        {
                            result = FMODPlatform.MobileLow;
                        }
                    }
                    catch
                    {
                        // Assume worst case
                        result = FMODPlatform.MobileLow;
                    }
                }
            }
            
            UnityEngine.Debug.Log(String.Format("FMOD Studio: Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
            return result;
            #elif UNITY_WINRT_8_1
            FMODPlatform result;
            if (SystemInfo.processorCount <= 2)
            {
                result = FMODPlatform.MobileLow;
            }
            else
            {
                result = FMODPlatform.MobileHigh;
            }

            UnityEngine.Debug.Log(String.Format("FMOD Studio: Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
            return result;

            #elif UNITY_PS4
            return FMODPlatform.PS4;
            #elif UNITY_XBOXONE
            return FMODPlatform.XboxOne;
            #elif UNITY_PSP2
            return FMODPlatform.PSVita;
            #elif UNITY_WIIU
            return FMODPlatform.WiiU;
            #endif
        }
Exemplo n.º 12
0
        /// <summary>
        /// Processes the file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="newMajorVersion">The new major version.</param>
        /// <param name="newMinorVersion">The new minor version.</param>
        /// <param name="newBuildVersion">The new build version.</param>
        /// <param name="newRevisionVersion">The new revision version.</param>
        /// <param name="newVersionSuffix">The new version suffix.</param>
        /// <param name="noRevision">If set to <c>true</c>, there is no revision in the final version.</param>
        /// <returns><c>true</c> if the document has been processed correctly, or <c>false</c> if it doesn't exist, or there is nothing to process.</returns>
        public bool ProcessFile(string fileName, int newMajorVersion, int newMinorVersion, int newBuildVersion, int newRevisionVersion = 0, string newVersionSuffix = null, bool noRevision = false)
        {
            if (!this.file.Exists(fileName))
            {
                return(false);
            }

            XDocument document;

            try
            {
                using (global::System.IO.Stream s = this.file.OpenRead(fileName))
                {
                    document = XDocument.Load(s, LoadOptions.PreserveWhitespace);
                }
            }
            catch
            {
                return(false);
            }

            XElement root = document.Root;

            if (root == null)
            {
                return(false);
            }

            XElement missingContainer = null;

            (var releaseVersion, var packageVersion, var fileVersion, var assemblyVersion)
                = VersionElementsHelper.VersionStrings(newMajorVersion, newMinorVersion, newBuildVersion, newRevisionVersion, newVersionSuffix, noRevision);

            var isCore = root.Attribute("Sdk")?.Value?.InvariantCultureEqualsInsensitive("Microsoft.NET.Sdk") ?? false;

            if (isCore)
            {
                IEnumerable <XElement> xVersions = root.Descendants("PropertyGroup").Descendants("Version");
                EnsureCorrectOnlyOneVersion(
                    missingContainer,
                    root,
                    xVersions,
                    packageVersion,
                    "Version");

                IEnumerable <XElement> xFileVersions = root.Descendants("PropertyGroup").Descendants("FileVersion");
                EnsureCorrectOnlyOneVersion(
                    missingContainer,
                    root,
                    xFileVersions,
                    fileVersion,
                    "FileVersion");

                IEnumerable <XElement> xAssemblyVersions = root.Descendants("PropertyGroup").Descendants("AssemblyVersion");
                EnsureCorrectOnlyOneVersion(
                    missingContainer,
                    root,
                    xAssemblyVersions,
                    assemblyVersion,
                    "AssemblyVersion");

                void EnsureCorrectOnlyOneVersion(XElement missingElementContainerBase, in XElement rootElementContainer, in IEnumerable <XElement> xElements, in string correctVersion, in string versionName)
                {
                    XElement xElement = xElements.FirstOrDefault();

                    if (xElement == null)
                    {
                        EnsureMissingContainerExists(missingElementContainerBase, rootElementContainer);

                        xElement = new XElement(versionName);

                        missingElementContainerBase.Add(xElement);

                        void EnsureMissingContainerExists(XElement missingElementContainer, in XElement rootContainer)
                        {
                            if (missingElementContainer != null)
                            {
                                return;
                            }

                            missingElementContainer = new XElement("PropertyGroup");

                            rootContainer.Add(missingElementContainer);
                        }
                    }

                    xElement.SetValue(correctVersion);

                    xElements.Where(p => p != xElement).ForEach(p => p.Remove());
                }

                using (global::System.IO.Stream s = this.file.Create(fileName))
                {
                    document.Save(s);
                }

                return(true);
            }
            else
            {
                var folderPath = this.path.GetDirectoryName(fileName);

                var foundAssemblyAttributes = false;

                this.directory
                .EnumerateFilesRecursively(folderPath, "*.cs")
#if NETSTANDARD1_0
                .ForEach(filePath =>
#else
                .ParallelForEach(filePath =>
#endif
                {
                    var lines = new List <string>();
                    var found = false;
                    using (global::System.IO.StreamReader handle = this.file.OpenText(filePath))
                    {
                        while (!handle.EndOfStream)
                        {
                            var line = handle.ReadLine();

                            if (!string.IsNullOrWhiteSpace(line))
                            {
                                Match versionMatch = AssemblyVersionRegex.Match(line);
                                if (versionMatch.Success)
                                {
                                    found = true;

                                    lines.Add($"[assembly: global::System.Reflection.AssemblyVersion(\"{assemblyVersion}\")]");
                                }
                                else
                                {
                                    Match assemblyVersionMatch = AssemblyFileVersionRegex.Match(line);
                                    if (assemblyVersionMatch.Success)
                                    {
                                        found = true;

                                        lines.Add($"[assembly: global::System.Reflection.AssemblyFileVersion(\"{fileVersion}\")]");
                                    }
                                    else
                                    {
                                        lines.Add(line);
                                    }
                                }
                            }
                            else
                            {
                                lines.Add(string.Empty);
                            }
                        }
                    }

                    if (found)
                    {
                        var finalText = string.Join(Environment.NewLine, lines);
                        using (global::System.IO.StreamWriter writeHandle = this.file.CreateText(filePath))
                        {
                            writeHandle.Write(finalText);
                        }

                        foundAssemblyAttributes = true;
                    }

                    lines.Clear();
                });

                return(foundAssemblyAttributes);
            }
        }