public WidgetList(WidgetList list)
 {
     foreach( DictionaryEntry elem in list )
     {
         this.Add(elem.Key, elem.Value);
     }            
 }
Exemplo n.º 2
0
        static public WidgetList xml2ModWidgets(XmlDocument doc)
        {
            XmlNode     root  = doc.DocumentElement;
            IEnumerator ienum = root.GetEnumerator();
            XmlNode     widgetXml;

            WidgetList list = new WidgetList();

            while (ienum.MoveNext())
            {
                widgetXml = (XmlNode)ienum.Current;
                WidgetInfo info = WidgetBrowser.xml2ModWidgetInfo(widgetXml);
                list.Add(info.id, info);
            }
            return(list);
        }
        /*
         * returns all widgets which contain one more of the files
         */
        private WidgetList getWidgetsThatContainFiles(WidgetList luas, ArrayList files)
        {
            WidgetList widgets = new WidgetList();

            IEnumerator ienum = luas.Values.GetEnumerator();
            while( ienum.MoveNext() )
            {
                //iterate widgets
                WidgetInfo curWidget = (WidgetInfo)ienum.Current;

                LinkedList<FileInfo> filesCurWidget = this.getFileListByLuaId(curWidget.id);
                ArrayList mis = this.getMissingFilesForWidget(filesCurWidget, files);

                if (mis.Count < filesCurWidget.Count )
                {
                    //at least one file is included, add the widget
                    widgets.Add(curWidget.id, curWidget);
                }
            }

            return widgets;
        }
Exemplo n.º 4
0
        /*
         * returns all widgets which contain one more of the files
         */
        private WidgetList getWidgetsThatContainFiles(WidgetList luas, ArrayList files)
        {
            WidgetList widgets = new WidgetList();

            IEnumerator ienum = luas.Values.GetEnumerator();

            while (ienum.MoveNext())
            {
                //iterate widgets
                WidgetInfo curWidget = (WidgetInfo)ienum.Current;

                LinkedList <FileInfo> filesCurWidget = this.getFileListByLuaId(curWidget.id);
                ArrayList             mis            = this.getMissingFilesForWidget(filesCurWidget, files);

                if (mis.Count < filesCurWidget.Count)
                {
                    //at least one file is included, add the widget
                    widgets.Add(curWidget.id, curWidget);
                }
            }

            return(widgets);
        }
Exemplo n.º 5
0
        //Array of modInfos
        public Dictionary <string, ModInfoDb> getActivationMods()
        {
            XmlDocument xml = this.doRequestXml(m_targetUrl + "?m=11");
            ArrayList   ar  = WidgetBrowser.xml2ModList(xml);

            Dictionary <string, ModInfoDb> result = new Dictionary <string, ModInfoDb>();

            foreach (ModInfoDb mod in ar)
            {
                try
                {
                    WidgetList modWidgets = this.getModWidgetsByModId(mod.id);
                    mod.modWidgets = modWidgets;
                    result.Add(mod.abbreviation, mod);
                }
                catch
                {
                    //hm what now?
                    //do nothing, nobody will ever know *hrhrhrhrhr*
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        public void Scan()
        {
            const string status = "Scanning mods";
            //Program.Notify(status);

            var pathsToAddPool = new List <string>();

            long totalSize = 0;

            List <string> searchPatterns = new List <string>();

            searchPatterns.Add("*.sdz");
            searchPatterns.Add("*.sd7");

            foreach (string pattern in searchPatterns)
            {
                foreach (var s in Directory.GetFiles(this.modFolder, pattern, SearchOption.TopDirectoryOnly))
                {
                    string name = Path.GetFileName(s);

                    if (modList.Find(delegate(ModInfoDb midb) { return(midb.modFilenames.Contains(name)); }) != null)
                    //if (modList.Find(m => (m.modFilenames.Contains(name).ToString() )) )
                    {
                        continue;
                    }

                    pathsToAddPool.Add(s);
                }
            }

            foreach (var s in pathsToAddPool)
            {
                try
                {
                    //do this first, so we are later able to skip file where error occured
                    ModInfoDb mod = new ModInfoDb();
                    mod.modFilenames.Add(Path.GetFileName(s));
                    this.modList.Add(mod);

                    ZipFile z = new ZipFile(s);

                    //read mod-shortname from modinfo.tdf
                    ZipEntry ze = z.GetEntry("modinfo.tdf");
                    if (ze == null)
                    {
                        //todo: check if modinfo.lua exists instead and parse it
                        continue;
                    }
                    Stream           modHeader = z.GetInputStream(ze);
                    MultiplatformIni ini       = new MultiplatformIni(modHeader);
                    string           shortname = ini.ReadString("MOD", "shortname");

                    if (shortname == null)
                    {
                        //this is not a mod, probably mission or something
                        continue;
                    }

                    mod.abbreviation = shortname.Trim(';');

                    WidgetList wlist = new WidgetList();
                    mod.modWidgets = wlist;

                    foreach (ZipEntry cur in z)
                    {
                        if (!cur.IsFile)
                        {
                            continue;
                        }

                        Match m = Regex.Match(cur.Name, ModBrowser.widgetKeyFileRegEx, RegexOptions.IgnoreCase);
                        if (m.Success)
                        {
                            try
                            {
                                TextReader reader = new StreamReader(z.GetInputStream(cur));
                                Dictionary <string, Object> widgetHeader = this.luaParser.getWidgetInfoHeaderString(reader.ReadToEnd());

                                WidgetInfo winfo = new WidgetInfo();
                                winfo.addFileHeaderInfo(widgetHeader);

                                wlist.Add(wlist.Count, winfo);
                            }
                            catch (Exception exp)
                            {
                                Console.WriteLine("ModWidget-Error in file \"" + s + "\" in widget \"" + cur.Name + "\": " + exp.Message);
                            }
                        }
                    }



                    //this.fileManager.readWidgetFile();
                    //  if (TaskManager.Cancel) break;
                    //                AddFile(s, totalSize, ref doneSize);
                }
                catch (Exception exp)
                {
                    Console.WriteLine("(Zip) Exception in file \"" + s + "\": " + exp.Message);
                }
            }


            SaveFileEntries();
            //Program.Notify("{0} complete", status);

            //if (pathsToAddPool.Count > 0 || todel.Count > 0) InvokeEvent(InstalledVersionsChanged);
        }
        static public WidgetList xml2ModWidgets(XmlDocument doc)
        {
            XmlNode root = doc.DocumentElement;
            IEnumerator ienum = root.GetEnumerator();
            XmlNode widgetXml;

            WidgetList list = new WidgetList();
            while (ienum.MoveNext())
            {
                widgetXml = (XmlNode)ienum.Current;
                WidgetInfo info = WidgetBrowser.xml2ModWidgetInfo(widgetXml);
                list.Add( info.id, info);
            }
            return list;
        }
        /*
         * Merges another list into this list
         */
        public void mergeAnotherList(WidgetList blist)
        {
            IDictionaryEnumerator ienum = blist.GetEnumerator();

            while (ienum.MoveNext())
            {
                int key = (int)ienum.Key;

                WidgetInfo info = (WidgetInfo)ienum.Value;
                if ( !this.ContainsKey(key))
                {
                    this.Add( key, info);
                }
            }
        }