Esempio n. 1
0
    public string INI_leggi(string section, string entry, string patch_value)
    {
//        MultiplatformIni ini  = new MultiplatformIni(AppDomain.CurrentDomain.BaseDirectory  + app_settings);
//		MultiplatformIni ini  = new MultiplatformIni();

        String default_Renamed = "";
        bool   patch           = true;

        sSection = section;
        sEntry   = entry;
        sDefault = default_Renamed;

        int chars = 256;

        byte[] sRetBuf = new byte[chars];
        iLenBuf = sRetBuf.Length;

        x = ini.ReadString(sSection, sEntry, sDefault);
        //x = GetPrivateProfileString(sSection, sEntry, sDefault, sRetBuf, chars, sFileName);
        if (x == "")
        {
            ini.WriteString(sSection, sEntry, patch_value);
        }

        sValue = x.ToString();
        return(sValue);
    }
Esempio n. 2
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);
        }