Beispiel #1
0
        private static StringArrayList GetTextualExtractor(object mimeType)
        {
            BibliographerSettings settings;

            string []       extractors;
            StringArrayList extractor;

            extractor  = new StringArrayList();
            settings   = new BibliographerSettings("apps.bibliographer.index");
            extractors = settings.GetStrv("textual-extractor");

            if (extractors.Length == 0)
            {
                ArrayList newExtractors;
                newExtractors = new ArrayList();

                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    // Default extractors for Windows systems
                    newExtractors.Add(".pdf:pdftotext:{0} -");
                    newExtractors.Add(".doc:antiword:{0}");
                    newExtractors.Add(".docx:opc_text:{0}");
                }
                else
                {
                    // Default extractors for Gnu/Linux systems
                    newExtractors.Add("application/pdf:pdftotext:{0} -");
                    newExtractors.Add("application/msword:antiword:{0}");
                    newExtractors.Add("application/postscript:pstotext:{0}");
                    newExtractors.Add("text/plain:cat:{0}");
                }

                //TODO: Add default extractors for other systems

                extractors = (string [])newExtractors.ToArray(typeof(string));
                settings.SetStrv("textual-extractor", extractors);
            }
            string [] output;

            foreach (string entry in extractors)
            {
                output = entry.Split(':');
                if (output [0] == mimeType.ToString())
                {
                    extractor.Add(output [1]);
                    extractor.Add(output [2]);
                }
            }

            if (extractor.Count > 0)
            {
                WriteLine(5, "textual extractor determined: " + extractor [0]);
            }

            return(extractor);
        }
        StringArrayList GetAuthors()
        {
            WriteLine(10, "SidePaneTreeStore.GetAuthors()");
            var authors = new StringArrayList();

            if (IterHasChild(iterAuth))
            {
                Gtk.TreeIter iter;

                IterChildren(out iter, iterAuth);

                while (IterIsValid(iter))
                {
                    string author = (string)GetValue(iter, 0);
                    WriteLine(10, "Add the Author {0} to an output list", author);
                    authors.Add(author);
                    if (!IterNext(ref iter))
                    {
                        break;
                    }
                }
            }
            authors.Sort();
            return(authors);
        }
Beispiel #3
0
        private static StringArrayList GetProcessOutput(string command, string args)
        {
            StringArrayList result = new StringArrayList();

            proc.StartInfo.FileName  = command;
            proc.StartInfo.Arguments = args;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.UseShellExecute        = false;
            try {
                proc.Start();

                while (true)
                {
                    string line = proc.StandardOutput.ReadLine();
                    if (line != null)
                    {
                        result.Add(line);
                    }
                    else
                    {
                        break;
                    }
                }

                if (proc.HasExited)
                {
                    if (proc.ExitCode == 0)
                    {
                        return(result);
                    }
                    WriteLine(5, "Running of program '{0}' with args '{1}' failed with exit code {2}", command, args, proc.ExitCode);
                    return(null);
                }
                WriteLine(5, "Read From File process, '{0}' did not exit, so it was killed", command);
                return(result);
            } catch (InvalidOperationException e) {
                WriteLine(1, "Caught InvalidOperationException");
                WriteLine(1, e.Message);
                WriteLine(1, e.StackTrace);
                return(null);
            } catch (FileNotFoundException e) {
                WriteLine(1, "Cannot Index file. Application '{0}' not found.", command);
                WriteLine(1, e.Message);
                WriteLine(1, e.StackTrace);
                return(null);
                // Why is this exception being thrown under linux???
            } catch (System.ComponentModel.Win32Exception e) {
                WriteLine(1, "Cannot Index file. Application '{0}' not found.", command);
                WriteLine(1, e.Message);
                WriteLine(1, e.StackTrace);
                return(null);
            } catch (Exception e) {
                WriteLine(1, "Caught Unhandled Exception");
                WriteLine(1, e.Message);
                WriteLine(1, e.StackTrace);
                return(null);
            }
        }
        void UpdateAuthors(BibtexRecord btRecord)
        {
            string          author;
            StringArrayList bibrecAuthors;

            bibrecAuthors = btRecord.GetAuthors();
            StringArrayList bibrecsAuthors;

            bibrecsAuthors = bibtexRecords.GetAuthors();

            // Interate through updated record's authors
            for (int ii = 0; ii < bibrecAuthors.Count; ii++)
            {
                author = bibrecAuthors[ii];
                // Insert Author
                StringArrayList treeAuthors = GetAuthors();
                if ((!treeAuthors.Contains(author)) && (author != null) && (author != ""))
                {
                    WriteLine(10, "Inserting Author {0} into Filter List", author);
                    AppendValues(iterAuth, author);
                }
            }

            // Iterate through tree and remove authors that are not in the bibtexRecords
            Gtk.TreeIter iter;
            var          treeAuth = new StringArrayList();

            IterChildren(out iter, iterAuth);
            int n = IterNChildren(iterAuth);

            for (int i = 0; i < n; i++)
            {
                string author1 = (string)GetValue(iter, 0);
                if (bibrecsAuthors.Contains(author1) && !treeAuth.Contains(author1))
                {
                    IterNext(ref iter);
                    treeAuth.Add(author1);
                }
                else
                {
                    WriteLine(10, "Removing Author {0} from Side Pane", author1);
                    Remove(ref iter);
                }
            }
        }
Beispiel #5
0
        protected override StringArrayList ExtractArchive()
        {
            StringArrayList ret = new StringArrayList();

            Ambertation.SevenZip.IO.CommandlineArchive a       = new Ambertation.SevenZip.IO.CommandlineArchive(this.ArchiveName);
            Ambertation.SevenZip.IO.ArchiveFile[]      content = a.ListContent();
            a.Extract(SimPe.Helper.SimPeTeleportPath, false);

            foreach (Ambertation.SevenZip.IO.ArchiveFile desc in content)
            {
                string rname = System.IO.Path.Combine(Helper.SimPeTeleportPath, desc.Name);
                if (System.IO.File.Exists(rname))
                {
                    ret.Add(rname);
                }
            }
            return(ret);
        }
        void InitialiseYears()
        {
            string          year;
            StringArrayList bibrecsYear;

            bibrecsYear = bibtexRecords.GetYears();
            for (int ii = 0; ii < bibrecsYear.Count; ii++)
            {
                year = bibrecsYear[ii];

                // Insert Year
                StringArrayList treeYear = GetYears();
                if ((!treeYear.Contains(year)) && (year != null) && (year != ""))
                {
                    WriteLine(10, "Inserting Year into Filter List");
                    AppendValues(iterYear, year);
                }
            }

            // Iterate through tree and remove years that are not in the bibtexRecords
            Gtk.TreeIter iter;
            var          treeYr = new StringArrayList();

            IterChildren(out iter, iterYear);
            int n = IterNChildren(iterYear);

            for (int i = 0; i < n; i++)
            {
                string year1 = (string)GetValue(iter, 0);
                if (bibrecsYear.Contains(year1) && !treeYr.Contains(year1))
                {
                    IterNext(ref iter);
                    treeYr.Add(year1);
                }
                else
                {
                    WriteLine(10, "Removing Year {0} from Side Pane", year1);
                    Remove(ref iter);
                }
            }
        }
        void InitialiseJournals()
        {
            string          journal;
            StringArrayList bibrecsJournals;

            bibrecsJournals = bibtexRecords.GetJournals();
            for (int ii = 0; ii < bibrecsJournals.Count; ii++)
            {
                journal = bibrecsJournals[ii];

                // Insert Journal
                StringArrayList treeJournals = GetJournals();
                if ((!treeJournals.Contains(journal)) && (journal != null) && (journal != ""))
                {
                    WriteLine(10, "Inserting Journal into Filter List");
                    AppendValues(iterJourn, journal);
                }
            }

            // Iterate through tree and remove journals that are not in the bibtexRecords
            var treeJourn = new StringArrayList();

            Gtk.TreeIter iter;
            IterChildren(out iter, iterJourn);
            int n = IterNChildren(iterJourn);

            for (int i = 0; i < n; i++)
            {
                string journal1 = (string)GetValue(iter, 0);
                if (bibrecsJournals.Contains(journal1) && !treeJourn.Contains(journal1))
                {
                    IterNext(ref iter);
                    treeJourn.Add(journal1);
                }
                else
                {
                    WriteLine(10, "Removing Journal {0} from Side Pane", journal1);
                    Remove(ref iter);
                }
            }
        }
    // Read an unlimited number of String; return an ArrayList
    public static StringArrayList GetStrings( )
    {
        StringArrayList array = new StringArrayList( );
        string          oneLine;

        Console.WriteLine("Enter any number of strings, one per line; ");
        Console.WriteLine("Terminate with empty line: ");
        try
        {
            while ((oneLine = Console.ReadLine( )) != null && oneLine != "")
            {
                array.Add(oneLine);
            }
        }
        catch (IOException)
        {
            Console.WriteLine("Unexpected IO Exception has shortened amount read");
        }
        Console.WriteLine("Done reading");
        return(array);
    }
        StringArrayList GetJournals()
        {
            var journals = new StringArrayList();

            if (IterHasChild(iterJourn))
            {
                Gtk.TreeIter iter;
                IterChildren(out iter, iterJourn);
                while (IterIsValid(iter))
                {
                    string journal = (string)GetValue(iter, 0);
                    journals.Add(journal);
                    if (!IterNext(ref iter))
                    {
                        break;
                    }
                }
            }
            journals.Sort();
            return(journals);
        }
        StringArrayList GetYears()
        {
            var years = new StringArrayList();

            if (IterHasChild(iterYear))
            {
                Gtk.TreeIter iter;
                IterChildren(out iter, iterYear);
                while (IterIsValid(iter))
                {
                    string year = (string)GetValue(iter, 0);
                    years.Add(year);
                    if (!IterNext(ref iter))
                    {
                        break;
                    }
                }
            }
            years.Sort();
            return(years);
        }
Beispiel #11
0
        protected override StringArrayList ExtractArchive()
        {
            StringArrayList ret = new StringArrayList();

            SimPe.Packages.S2CPDescriptor[] content = SimPe.Packages.Sims2CommunityPack.Open(this.ArchiveName);

            foreach (SimPe.Packages.S2CPDescriptor desc in content)
            {
                string name = System.IO.Path.Combine(Helper.SimPeTeleportPath, desc.Name);
                string rname = name; int ct = 0;
                while (System.IO.File.Exists(rname))
                {
                    rname = System.IO.Path.Combine(Helper.SimPeTeleportPath, ct.ToString() + "_" + desc.Name);
                    ct++;
                }
                desc.Package.Save(rname);
                if (System.IO.File.Exists(rname))
                {
                    ret.Add(rname);
                }
            }
            return(ret);
        }
Beispiel #12
0
        private SimPe.StringArrayList SortFilesByType(SimPe.StringArrayList files)
        {
            SimPe.StringArrayList objects = new StringArrayList();
            SimPe.StringArrayList other   = new StringArrayList();
            foreach (string file in files)
            {
                SimPe.Cache.PackageType type = PackageInfo.ClassifyPackage(file);
                SimPe.Plugin.DownloadsToolFactory.TeleportFileIndex.AddIndexFromPackage(file);

                if (type == SimPe.Cache.PackageType.Object || type == SimPe.Cache.PackageType.MaxisObject || type == SimPe.Cache.PackageType.Sim)
                {
                    objects.Add(file);
                }
                else
                {
                    other.Add(file);
                }
            }
            objects.AddRange(other);
            other.Clear(); other = null;
            files.Clear(); files = null;

            return(objects);
        }