示例#1
0
 private async Task <LauncherData.StaticTabData> getStaticTabData(string uiKey, string url, string quoteToEscape, string replacePlaceholder)
 {
     LauncherData.StaticTabData staticTabData = new LauncherData.StaticTabData();
     staticTabData.Site = url;
     try {
         if (Program.LoncherSettings.UIStyle.TryGetValue(uiKey, out FileInfo fileInfo))
         {
             if (fileInfo != null && YU.stringHasText(fileInfo.Url))
             {
                 using (WebClient wc = new WebClient {
                     Encoding = Encoding.UTF8
                 }) {
                     string template = (await wc.DownloadStringTaskAsync(new Uri(fileInfo.Url)));
                     string cl       = "";
                     if (url != null && url.Length > 0)
                     {
                         cl = (await wc.DownloadStringTaskAsync(new Uri(url)));
                         if (quoteToEscape != null && quoteToEscape.Length > 0)
                         {
                             string quote = quoteToEscape;
                             cl = cl.Replace("\\", "\\\\").Replace(quote, "\\" + quote);
                             if (cl.Contains("\r"))
                             {
                                 cl = cl.Replace("\r\n", "\\\r\n");
                             }
                             else
                             {
                                 cl = cl.Replace("\n", "\\\n");
                             }
                         }
                     }
                     staticTabData.Html = template.Replace(replacePlaceholder, cl);
                 }
             }
         }
     }
     catch (Exception ex) {
         staticTabData.Error = ex.Message;
     }
     return(staticTabData);
 }
示例#2
0
 private async Task <LauncherData.StaticTabData> getStaticTabData(string uiKey, string url, string quoteToEscape, string replacePlaceholder)
 {
     LauncherData.StaticTabData staticTabData = new LauncherData.StaticTabData();
     staticTabData.Site = url;
     try {
         if (Program.LoncherSettings.UIStyle.TryGetValue(uiKey, out FileInfo changelogFileInfo))
         {
             if (await assertFile(changelogFileInfo, TMPLPATH))
             {
                 string changelogTemplate = File.ReadAllText(TMPLPATH + changelogFileInfo.Path, Encoding.UTF8);
                 string cl = "";
                 if (url != null && url.Length > 0)
                 {
                     cl = (await wc_.DownloadStringTaskAsync(new Uri(url)));
                     File.WriteAllText(TMPLPATH + "tempLast" + uiKey, cl, Encoding.UTF8);
                     if (quoteToEscape != null && quoteToEscape.Length > 0)
                     {
                         string quote = quoteToEscape;
                         cl = cl.Replace("\\", "\\\\").Replace(quote, "\\" + quote);
                         if (cl.Contains("\r"))
                         {
                             cl = cl.Replace("\r\n", "\\\r\n");
                         }
                         else
                         {
                             cl = cl.Replace("\n", "\\\n");
                         }
                     }
                 }
                 staticTabData.Html = changelogTemplate.Replace(replacePlaceholder, cl);
             }
         }
     }
     catch (Exception ex) {
         staticTabData.Error = ex.Message;
     }
     return(staticTabData);
 }