コード例 #1
0
ファイル: QueueControl.cs プロジェクト: maesse/NZBHags
 public QueueControl(FileCollection collection, MainGUI gui)
 {
     this.gui = gui;
     this.collection = collection;
     InitializeComponent();
     UpdateUI();
 }
コード例 #2
0
ファイル: NZBFileHandler.cs プロジェクト: maesse/NZBHags
        // Loads an .nzb file
        public static FileCollection loadFile(string filename)
        {
            // Loadtime measuring
            Performance.Stopwatch sw = new Performance.Stopwatch();
            sw.Start();

            XmlDocument document = new XmlDocument();
            FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            // Inits xmlreader with custom resolver for instant dtd file lookup
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ProhibitDtd = false;
            settings.XmlResolver = new XmlFileResolver();

            // Create new FIleCOllection object

            FileCollection collection = new FileCollection(getPrettyFilename(filename));

            // Parse file into XmlDocument
            document.Load(XmlReader.Create(stream, settings));
            stream.Close();

            List<FileJob> files = ParseXML(document, collection);
            collection.files = files;

            // Calculate collection size
            collection.CalculateTotalSize();
            // Loadtime measuring
            sw.Stop();
            Logging.Instance.Log("Loading {0}. Took {1}ms", filename, sw.GetElapsedTimeSpan().TotalMilliseconds);
            return collection;
        }
コード例 #3
0
ファイル: Par2Handler.cs プロジェクト: maesse/NZBHags
 // Adds a collection to be handled
 public void AddCollection(FileCollection collection)
 {
     //lock (collections)
     //{
     //    collections.Add(collection);
     //}
     HandleCollection(collection);
 }
コード例 #4
0
ファイル: QueueHandler.cs プロジェクト: maesse/NZBHags
 public void AddCollection(FileCollection collection)
 {
     collection.status = CollectionStatus.QUEUED;
     //collection.queue = NZBFileHandler.genQueue(collection.files);
     collection.id = nextId;
     nextId++;
     collections.Add(collection);
     changed = true;
 }
コード例 #5
0
ファイル: FileJob.cs プロジェクト: maesse/NZBHags
 public FileJob(ref FileCollection parent)
 {
     status = FileJobStatus.QUEUED;
     saveprogress = 0;
     this.parent = parent;
     Random random = new Random();
     filename = ""+random.Next(99999);
     segments = new List<Segment>();
     groups = new ArrayList();
     complete = false;
 }
コード例 #6
0
ファイル: QueueHandler.cs プロジェクト: maesse/NZBHags
 public FileCollection[] getCollections()
 {
     FileCollection[] coll = new FileCollection[collections.Count];
     for (int i = 0; i < nextId; i++)
     {
         foreach (FileCollection col in collections)
         {
             if (col.id == i)
             {
                 coll[i] = col;
                 break;
             }
         }
     }
     return coll;
 }
コード例 #7
0
ファイル: Par2Handler.cs プロジェクト: maesse/NZBHags
        // Starting point for handling a collection
        private void HandleCollection(FileCollection collection)
        {
            idle = false;

            StringBuilder strBuilder = new StringBuilder();
            string mainPar2filename = null;
            string dir = Properties.Settings.Default.outputPath + "\\" + collection.name;

            string[] files = Directory.GetFiles(dir);

            for (int i = 0; i < files.Length; i++)
            {
                if (mainPar2filename == null && files[i].EndsWith(".par2"))
                    mainPar2filename = files[i];
                System.Console.WriteLine(files[i]);
            }

            idle = true;
        }
コード例 #8
0
ファイル: QueueHandler.cs プロジェクト: maesse/NZBHags
 public void setCollectionID(FileCollection col, int index)
 {
     if (index >= 0 && index < nextId)
     {
         if (col.id > index)
         {
             // decrement
             foreach (FileCollection collection in collections)
             {
                 if(collection.id == index) {
                     collection.id++;
                     break;
                 }
             }
             col.id--;
         }
         else
         {
             // increment
             foreach (FileCollection collection in collections)
             {
                 if (collection.id == index)
                 {
                     collection.id--;
                     break;
                 }
             }
             col.id++;
         }
     }
     changed = true;
 }
コード例 #9
0
ファイル: QueueHandler.cs プロジェクト: maesse/NZBHags
 public void removeCollection(FileCollection collection)
 {
     if (currentFileJob != null && currentFileJob.parent == collection)
         currentFileJob = null;
     if (collection.id != nextId - 1)
     {
         for (int i = collection.id + 1; i < nextId; i++)
         {
             foreach (FileCollection col in collections)
             {
                 if (col.id == i)
                 {
                     col.id--;
                     break;
                 }
             }
         }
     }
     else
         nextId--;
     collections.Remove(collection);
     changed = true;
 }
コード例 #10
0
ファイル: NZBFileHandler.cs プロジェクト: maesse/NZBHags
        //// Generates queues for a filecollection object
        //public static Queue genQueue(ArrayList list)
        //{
        //    Queue queue = new Queue(list.Count);
        //    foreach (FileJob job in list)
        //    {
        //        job.queue = new Queue(job.segments.Count);
        //        foreach (Segment seg in job.segments)
        //        {
        //            job.queue.Enqueue(seg);
        //        }
        //        queue.Enqueue(job);
        //    }
        //    return queue;
        //}
        // Parses XML structure into file objects
        private static List<FileJob> ParseXML(XmlDocument document, FileCollection filecollection)
        {
            XmlNodeList nodes = document.GetElementsByTagName("file");
            List<FileJob> files = new List<FileJob>();
            Random random = new Random();
            int collectionID = random.Next();
            int fileId = 0;
            // Parsing for each file node
            foreach (XmlElement fileNode in nodes)
            {
                FileJob filejob = new FileJob(ref filecollection);
                filejob.filename = ""+collectionID;
                XmlAttributeCollection collection = fileNode.Attributes;

                // File Attributes
                foreach (XmlAttribute attr in collection)
                {
                    switch (attr.Name)
                    {
                        case "poster":
                            filejob.poster = attr.Value;
                            break;
                        case "date":
                            filejob.date = int.Parse(attr.Value);
                            break;
                        case "subject":
                            if (attr.Value.Contains("\""))
                            {
                                // try to get inner filename...
                                try
                                {
                                    int first = attr.Value.IndexOf("\"") + 1;
                                    string filename = attr.Value.Substring(first, attr.Value.Length - first);
                                    filename = filename.Substring(0, filename.IndexOf("\""));
                                    filejob.filename = filejob.filename + "-"+ filename.Substring(0, filename.LastIndexOf(".")+4);
                                }
                                catch (Exception ex)
                                {
                                    filejob.filename = filejob.filename+"-"+fileId;
                                }

                            }
                            else
                                filejob.filename = filejob.filename + "-" + fileId;

                            filejob.subject = attr.Value;
                            break;
                    }
                }
                int maxnumber = 0;
                foreach (XmlElement subNode in fileNode.ChildNodes)
                {
                    if (subNode.Name == "segments")
                    {
                        foreach (XmlElement segmentNode in subNode)
                        {
                            Segment segment = new Segment();
                            segment.addr = "<"+segmentNode.InnerXml+">";
                            segment.addr = segment.addr.Replace("&amp;", "&");
                            segment.setParent(ref filejob);
                            foreach (XmlAttribute attr in segmentNode.Attributes)
                            {
                                switch (attr.Name)
                                {
                                    case "bytes":
                                        segment.bytes = int.Parse(attr.Value);
                                        filejob.size += (ulong)segment.bytes;
                                        break;
                                    case "number":
                                        segment.id = int.Parse(attr.Value);
                                        if (segment.id > maxnumber)
                                            maxnumber = segment.id;
                                        break;
                                }
                            }

                            // Check and add element to arraylist
                            if (segment.id != 0 && segment.bytes != 0 && segment.addr.Length > 10)
                                filejob.segments.Add(segment);
                        }
                    } else if (subNode.Name == "groups")
                    {
                        filejob.groups.Add(subNode.FirstChild.InnerText);
                    }
                }
                filejob.yparts = maxnumber; // Will fail if source isnt yenc
                // Sort segments
                filejob.segments.Sort(new SegmentComparer());

                files.Add(filejob);
                fileId++;
            }
            return files;
        }