Beispiel #1
0
        private void loadFromFile()
        {
            addonList.Clear();
            string line = null;

            System.IO.StreamReader file = new System.IO.StreamReader(process.getFileName());
            while ((line = file.ReadLine()) != null)
            {
                if (line[0] == Properties.Resources.FILE_META_LINE_CHARACTER[0])
                {
                    int    firstSpaceIndex = line.IndexOf(' ');
                    string marker          = line.Substring(0, firstSpaceIndex);
                    if (marker.Equals(createDateMarker))
                    {
                        createDate.Content = line.Substring(firstSpaceIndex, line.Length - firstSpaceIndex).Trim();
                    }
                    else if (marker.Equals(limitMaker))
                    {
                        limitParam.Content = line.Substring(firstSpaceIndex, line.Length - firstSpaceIndex).Trim();
                    }
                }
                else
                {
                    String[]    addonParams = line.Split(Properties.Resources.FILE_SEPARATOR_CHARACTER[0]);
                    AddonEntity addonItem   = createAddonFromFileParams(addonParams);
                    addonList.Add(addonItem);
                }
            }
            file.Close();
            refreshAddonTabControl();
        }
 private void getAddonAndDate(IEnumerable <HtmlNode> pageNodes, int pageNumber)
 {
     try
     {
         AddonEntity addon = null;
         foreach (HtmlNode hnode in pageNodes)
         {
             //addon title, download link, addon type
             if (hnode.Name == "div" && hnode.Attributes["class"] != null && hnode.Attributes["class"].Value == "post")
             {
                 if (hnode.FirstChild.NextSibling.Name == "h2" && hnode.FirstChild.NextSibling.FirstChild.Name == "a")
                 {
                     addon           = new AddonEntity();
                     addon.ListIndex = ++addonCounter;
                     addon.Type      = ADDON_TYPES.GAME;
                     addon.Name      = hnode.FirstChild.NextSibling.InnerText;
                     addon.AddonURL  = hnode.FirstChild.NextSibling.FirstChild.Attributes[0].Value;
                 }
             }
             //addon date
             if (hnode.Name == "div" && hnode.Attributes["class"] != null && hnode.Attributes["class"].Value == "meta")
             {
                 if (addon != null)
                 {
                     string dateString   = hnode.FirstChild.InnerHtml.Substring(hnode.FirstChild.InnerHtml.IndexOf(' '), hnode.FirstChild.InnerHtml.IndexOf(' ') + 6).Trim();
                     string addonDateDay = dateString.Substring(0, 3).Trim();
                     if (addonDateDay[0] == '0')
                     {
                         addonDateDay = dateString.Substring(1, 2).Trim();
                     }
                     addon.Day = Int32.Parse(addonDateDay);
                     string addonDateMonth = dateString.Substring(3, 3).Trim();
                     addon.Month = utils.Utils.getMonthIndexFromName(addonDateMonth);
                     string addonDateYear = dateString.Substring(6, 5).Trim();
                     addon.Year = Int32.Parse(addonDateYear);
                     addon.Page = currentPage;
                     addonList.Add(addon);
                 }
             }
         }
     }
     catch (System.NullReferenceException ex)
     {
         Console.WriteLine("SkidrowrelodedParserProcess getAddonAndDate NullReferenceException: " + ex.StackTrace, ex);
     }
     catch (System.Exception ex)
     {
         Console.WriteLine("SkidrowrelodedParserProcess getAddonAndDate Exception: " + ex.StackTrace, ex);
     }
 }
Beispiel #3
0
        private AddonEntity createAddonFromFileParams(String[] addonParams)
        {
            AddonEntity addon = new AddonEntity();

            addon.ListIndex = Int32.Parse(addonParams[0]);                //linenumber
            addon.Type      = AddonTypeConverter.GetType(addonParams[1]); //type
            addon.Name      = addonParams[2];                             //name
            addon.AddonURL  = addonParams[3];                             //addonURL
            addon.Page      = Int32.Parse(addonParams[4]);                //page
            addon.Year      = Int32.Parse(addonParams[5]);                //year
            addon.Month     = Int32.Parse(addonParams[6]);                //month
            addon.Day       = Int32.Parse(addonParams[7]);                //day
            return(addon);
        }
Beispiel #4
0
        private void getAddonAndDate(IEnumerable <HtmlNode> pageNodes, int pageNumber)
        {
            try
            {
                AddonEntity addon = null;
                foreach (HtmlNode hnode in pageNodes)
                {
                    //addon title
                    if (hnode.Name == "h2")
                    {
                        var classVal = hnode.Attributes["class"];
                        if (classVal.Value == "title")
                        {
                            addon = new AddonEntity(ADDON_TYPES.NONE, pageNumber);
                            String addonTitle = hnode.InnerText.
                                                Replace("&#8211;", "-").
                                                Replace("&#038;", "&").
                                                Replace("&#8220;", "'").
                                                Replace("&#8221;", "'").
                                                Replace("&#160;", "@").
                                                Replace("&#8216;", "'").
                                                Replace("&#8217;", "'").
                                                Replace("&#215;", "x");
                            addon.Name      = addonTitle;
                            addon.ListIndex = addonList.Count + 1;
                            //Console.WriteLine(addonTitle);
                        }
                        //download link
                        var links = hnode.Descendants("a").Select(node => node.GetAttributeValue("href", "")).ToList();
                        addon.AddonURL = links[0];
                    }
                    //addon date
                    var classValue = hnode.Attributes["class"];
                    if (classValue != null && classValue.Value == "meta_date")
                    {
                        String addonDate = hnode.InnerText;
                        addon.Year  = Int32.Parse(addonDate.Substring(0, 4));
                        addon.Month = Int32.Parse(addonDate.Substring(5, 2));
                        addon.Day   = Int32.Parse(addonDate.Substring(8, 2));
                        //Console.WriteLine("year: " + addon.Year + " month: " + addon.Month + " day: " + addon.Day);
                    }
                    //addon type
                    if (classValue != null && classValue.Value == "meta_categories")
                    {
                        String addonType = hnode.InnerText;
                        if (addonType != null && addonType.Any())
                        {
                            switch (addonType.ToLower())
                            {
                            case "trucks": addon.Type = ADDON_TYPES.TRUCK_MOD; break;

                            case "trailers": addon.Type = ADDON_TYPES.TRAILER_MOD; break;

                            case "interiors": addon.Type = ADDON_TYPES.INTERIOR_MOD; break;

                            case "interior addons": addon.Type = ADDON_TYPES.INTERIOR_ADDON; break;

                            case "parts/tuning": addon.Type = ADDON_TYPES.PARTS_TUNING_MOD; break;

                            case "ai traffic": addon.Type = ADDON_TYPES.AI_TRAFFIC; break;

                            case "sounds": addon.Type = ADDON_TYPES.SOUND_MOD; break;

                            case "truck skins": addon.Type = ADDON_TYPES.TRUCK_SKIN; break;

                            case "combo skin packs": addon.Type = ADDON_TYPES.COMBO_SKIN_PACKS; break;

                            case "maps": addon.Type = ADDON_TYPES.MAPS; break;

                            case "cars": addon.Type = ADDON_TYPES.CARS; break;

                            case "others": addon.Type = ADDON_TYPES.OTHERS; break;

                            default: addon.Type = ADDON_TYPES.NOT_DEFINED; break;
                            }
                        }
                        else
                        {
                            addon.Type = ADDON_TYPES.NOT_DEFINED;
                        }
                        addon.ListIndex = ++addonCounter;
                        addonList.Add(addon);
                        //Console.WriteLine(addon.Type);
                    }
                    //next page
                    if (classValue != null && classValue.Value == "next")
                    {
                        pageURL = hnode.Attributes["href"].Value;
                        //Console.WriteLine("next page: " + pageURL);
                        break;
                    }
                }
            }
            catch (System.NullReferenceException ex)
            {
                Console.WriteLine("getAddonAndDate NullReferenceException: " + ex.StackTrace);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("getAddonAndDate Exception: " + ex.StackTrace);
            }
        }