Esempio n. 1
0
        public static Image GetImage(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(null);
            }

            Image image = null;

            try
            {
                using (WebClient webClient = new WebClient())
                {
                    webClient.Headers.Set("User-Agent", "Depressurizer");

                    byte[] imageBytes = webClient.DownloadData(url);
                    using (MemoryStream memoryStream = new MemoryStream(imageBytes))
                    {
                        image = Image.FromStream(memoryStream);
                    }
                }
            }
            catch (Exception e)
            {
                SentryLogger.Log(e);
            }

            return(image);
        }
Esempio n. 2
0
        /// <summary>
        ///     Steam AppInfo.vdf Reader
        /// </summary>
        /// <param name="path">appinfo.vdf path</param>
        public AppInfoReader(string path)
        {
            try
            {
                _fileStream   = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                _binaryReader = new BinaryReader(_fileStream);

                // Read some header fields
                _binaryReader.ReadByte();
                if ((_binaryReader.ReadByte() != 0x44) || (_binaryReader.ReadByte() != 0x56))
                {
                    throw new InvalidDataException("Invalid VDF format");
                }

                // Skip more header fields
                _binaryReader.ReadBytes(5);

                while (true)
                {
                    uint id = _binaryReader.ReadUInt32();
                    if (id == 0)
                    {
                        break;
                    }

                    // Skip unused fields
                    _binaryReader.ReadBytes(44);

                    // Load details
                    Items[id] = ReadEntries();
                }
            }
            catch (Exception e)
            {
                SentryLogger.Log(e);
                throw;
            }
            finally
            {
                if (_fileStream != null)
                {
                    _fileStream.Dispose();
                }

                if (_binaryReader != null)
                {
                    _binaryReader.Dispose();
                }
            }
        }
Esempio n. 3
0
 private void FlushLog()
 {
     lock (SyncRoot)
     {
         try
         {
             while (LogQueue.Count > 0)
             {
                 LogQueue.TryDequeue(out string logEntry);
                 byte[] output = new UTF8Encoding().GetBytes(logEntry + Environment.NewLine);
                 _outputStream.Write(output, 0, output.Length);
             }
         }
         catch (Exception e)
         {
             SentryLogger.Log(e);
         }
     }
 }
Esempio n. 4
0
        public static CultureInfo GetCultureInfoFromStoreLanguage(StoreLanguage storeLanguage)
        {
            CultureInfo cultureInfo = CultureInfo.CurrentCulture;

            try
            {
                string language = storeLanguage == StoreLanguage.Default ? Settings.Instance.InterfaceLanguage.ToString() : storeLanguage.ToString();

                foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
                {
                    if (culture.EnglishName == language)
                    {
                        cultureInfo = culture;
                    }
                }
            }
            catch (Exception e)
            {
                SentryLogger.Log(e);
            }

            return(cultureInfo);
        }
Esempio n. 5
0
        /// <inheritdoc />
        public void Dispose()
        {
            lock (SyncRoot)
            {
                try
                {
                    FlushLog();

                    byte[] output = new UTF8Encoding().GetBytes(Environment.NewLine);
                    _outputStream.Write(output, 0, output.Length);

                    _outputStream.Flush();
                    _outputStream.Flush(true);
                    _outputStream.Dispose();
                    _outputStream.Close();
                    _outputStream = null;
                    _instance     = null;
                }
                catch (Exception e)
                {
                    SentryLogger.Log(e);
                }
            }
        }
Esempio n. 6
0
        private static void FetchBanner(int appId)
        {
            if ((appId <= 0) || File.Exists(Location.File.Banner(appId)) || IgnoreList.Contains(appId))
            {
                return;
            }

            string bannerLink = string.Format(CultureInfo.InvariantCulture, "https://steamcdn-a.akamaihd.net/steam/apps/{0}/capsule_sm_120.jpg", appId);

            try
            {
                using (WebClient webClient = new WebClient())
                {
                    webClient.DownloadFile(bannerLink, Location.File.Banner(appId));
                }
            }
            catch (WebException we)
            {
                if (we.InnerException is IOException)
                {
                    Thread.Sleep(100);
                    FetchBanner(appId);
                }

                if (we.Response is HttpWebResponse errorResponse && (errorResponse.StatusCode != HttpStatusCode.NotFound))
                {
                    throw;
                }

                Logger.Instance.Warn("Couldn't fetch banner for appId: {0}", appId);
            }
            catch (Exception e)
            {
                SentryLogger.Log(e);
            }
        }