예제 #1
0
        public static decimal GetGitVersion(int GitID)
        {
            try {
                string xml = Networking.GetJsonToXml(string.Format(GitData.GitLinks.GithubLatestJson, GitData.GitLinks.Users[GitID], GitData.GitLinks.ApplciationNames[GitID]));

                if (xml == null)
                {
                    return(-1);
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlNodeList xmlTag = doc.DocumentElement.SelectNodes("/root/tag_name");

                if (GitID == 0)
                {
                    XmlNodeList xmlName = doc.DocumentElement.SelectNodes("/root/name");
                    XmlNodeList xmlBody = doc.DocumentElement.SelectNodes("/root/body");


                    GitData.UpdateVersion = xmlTag[0].InnerText;
                    GitData.UpdateName    = xmlName[0].InnerText;
                    GitData.UpdateBody    = xmlBody[0].InnerText;
                    return(GitData.GitLinks.GetGitVersionDecimal(GitData.UpdateVersion));
                }
                else
                {
                    return(-1);
                }
            }
            catch (Exception ex) {
                ErrorLog.ReportException(ex);
                return(-1);
            }
        }
예제 #2
0
 public static string LoadThreads()
 {
     try {
         if (System.IO.File.Exists(Program.ApplicationFilesLocation + "\\threads.dat"))
         {
             return(System.IO.File.ReadAllText(Program.ApplicationFilesLocation + "\\threads.dat").Replace("\r", "").Trim('\n'));
         }
         return(string.Empty);
     }
     catch (Exception ex) {
         ErrorLog.ReportException(ex);
         return(string.Empty);
     }
 }
예제 #3
0
        public static string GetJSON(string InputURL, DateTime ModifiedSince = default(DateTime))
        {
            try {
                string JSONOutput = null;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(InputURL);
                Request.UserAgent = YChanEx.Advanced.Default.UserAgent;
                Request.Method    = "GET";
                if (ModifiedSince != default(DateTime))
                {
                    Request.IfModifiedSince = ModifiedSince;
                }
                var Response       = (HttpWebResponse)Request.GetResponse();
                var ResponseStream = Response.GetResponseStream();
                using (StreamReader Reader = new StreamReader(ResponseStream)) {
                    string JSONString = Reader.ReadToEnd();
                    byte[] JSONBytes  = Encoding.ASCII.GetBytes(JSONString);
                    using (var MemoryStream = new MemoryStream(JSONBytes)) {
                        var Quotas     = new XmlDictionaryReaderQuotas();
                        var JSONReader = JsonReaderWriterFactory.CreateJsonReader(MemoryStream, Quotas);
                        var XMLJSON    = XDocument.Load(JSONReader);
                        JSONOutput = XMLJSON.ToString();
                        MemoryStream.Flush();
                        MemoryStream.Close();
                    }
                }
                ResponseStream.Dispose();
                Response.Dispose();

                GC.Collect();

                if (JSONOutput != null)
                {
                    if (JSONOutput != EmptyXML)
                    {
                        return(JSONOutput);
                    }
                }

                return(null);
            }
            catch (WebException WebEx) {
                ErrorLog.ReportWebException(WebEx, InputURL);
                return(null);
            }
            catch (Exception ex) {
                ErrorLog.ReportException(ex);
                return(null);
            }
        }
예제 #4
0
 public static bool IsUpdateAvailable(decimal cloudVersion)
 {
     try {
         if (Properties.Settings.Default.AppVersion < cloudVersion)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex) {
         ErrorLog.ReportException(ex);
         return(false);
     }
 }
예제 #5
0
        public static bool DownloadFile(string FileURL, string Destination, string FileName, bool RequireCookie = false, string RequiredCookie = null)
        {
            try {
                if (!Directory.Exists(Destination))
                {
                    Directory.CreateDirectory(Destination);
                }
                using (WebClientMethod wc = new WebClientMethod()) {
                    wc.Method = "GET";
                    wc.Headers.Add(HttpRequestHeader.UserAgent, YChanEx.Advanced.Default.UserAgent);
                    if (RequireCookie && !string.IsNullOrEmpty(RequiredCookie))
                    {
                        wc.Headers.Add(HttpRequestHeader.Cookie, RequiredCookie);
                    }
                    string FullFileName = Destination + "\\" + FileName;

                    if (FullFileName.Length > 255 && !Downloads.Default.AllowFileNamesGreaterThan255)
                    {
                        string FileExtension = FileName.Split('.')[FileName.Split('.').Length - 1];
                        string OldFileName   = FileName;
                        FileName = FullFileName.Substring(0, (255 - FileExtension.Length - 1));
                        File.WriteAllText(Destination + "\\" + FileName + ".txt", OldFileName);

                        FullFileName = Destination + "\\" + FileName;
                    }

                    if (!File.Exists(FullFileName))
                    {
                        wc.DownloadFile(FileURL, FullFileName);
                    }
                }

                return(true);
            }
            catch (WebException WebEx) {
                ErrorLog.ReportWebException(WebEx, FileURL);
                return(false);
            }
            catch (Exception Ex) {
                ErrorLog.ReportException(Ex);
                return(false);
            }
        }
예제 #6
0
        public static bool SaveThreads(List <string> ThreadURLs, List <ThreadStatus> ThreadStatus)
        {
            if (General.Default.SaveQueueOnExit)
            {
                try {
                    string FileContentBuffer = string.Empty;
                    for (int i = 0; i < ThreadURLs.Count; i++)
                    {
                        FileContentBuffer += ThreadURLs[i].Replace("=", "%61").Replace("|", "%124") + " = " + ThreadStatus[i].ToString() + "\n";
                    }
                    FileContentBuffer = FileContentBuffer.Trim('\n');

                    File.WriteAllText(Program.ApplicationFilesLocation + "\\threads.dat", FileContentBuffer);
                    return(true);
                }
                catch (Exception ex) {
                    ErrorLog.ReportException(ex);
                    return(false);
                }
            }
            return(false);
        }
예제 #7
0
        public static string GetHTML(string InputURL, bool RequireCookie = false, string RequiredCookie = null)
        {
            try {
                using (WebClient wc = new WebClient()) {
                    wc.Headers.Add("User-Agent: " + YChanEx.Advanced.Default.UserAgent);

                    if (RequireCookie && !string.IsNullOrEmpty(RequiredCookie))
                    {
                        wc.Headers.Add(HttpRequestHeader.Cookie, RequiredCookie);
                    }

                    return(wc.DownloadString(InputURL));
                }
            }
            catch (WebException WebEx) {
                ErrorLog.ReportWebException(WebEx, InputURL);
                return(null);
            }
            catch (Exception Ex) {
                ErrorLog.ReportException(Ex);
                return(null);
            }
        }
예제 #8
0
        public static void CheckForUpdate(bool ForceCheck = false)
        {
            if (Program.IsDebug)
            {
                //    Debug.Print("-version " + GitData.UpdateVersion + " -name " + System.AppDomain.CurrentDomain.FriendlyName);
                return;
            }

            if (!General.Default.EnableUpdates && !ForceCheck)
            {
                return;
            }


            if (GitData.UpdateAvailable)
            {
                using (frmUpdateAvailable Update = new frmUpdateAvailable()) {
                    Update.BlockSkip = ForceCheck;
                    switch (Update.ShowDialog())
                    {
                    case DialogResult.Yes:
                        try {
                            UpdateApplication();
                        }
                        catch (Exception ex) {
                            ErrorLog.ReportException(ex);
                            return;
                        }
                        break;
                    }
                }
            }
            else
            {
                Thread checkUpdates = new Thread(() => {
                    if (GitData.UpdateVersion == "-1" || ForceCheck)
                    {
                        decimal GitVersion = GetGitVersion(0);
                        if (IsUpdateAvailable(GitVersion))
                        {
                            GitData.UpdateAvailable = true;
                            if (GitVersion != Properties.Settings.Default.SkippedVersion || ForceCheck)
                            {
                                using (frmUpdateAvailable Update = new frmUpdateAvailable()) {
                                    Update.BlockSkip = ForceCheck;
                                    switch (Update.ShowDialog())
                                    {
                                    case DialogResult.Yes:
                                        try {
                                            UpdateApplication();
                                        }
                                        catch (Exception ex) {
                                            ErrorLog.ReportException(ex);
                                            return;
                                        }
                                        break;

                                    case DialogResult.Ignore:
                                        Properties.Settings.Default.SkippedVersion = GitVersion;
                                        Properties.Settings.Default.Save();
                                        break;
                                    }
                                }
                            }
                        }
                        else if (ForceCheck)
                        {
                            MessageBox.Show("No updates available.");
                        }
                    }
                });
                checkUpdates.Name = "Check for application update";
                checkUpdates.Start();
            }
        }