Esempio n. 1
0
        public GpkPackage loadSubGpk(string path, CompositeMapEntry entry)
        {
            var reader = new Reader();
            var gpk    = reader.ReadSubGpkFromComposite(path, entry.UID, entry.FileOffset, entry.FileLength);

            if (gpk == null)
            {
                return(null);
            }

            gpk.CompositeGpk   = true;
            gpk.CompositeEntry = entry;
            LoadedGpkPackages.Add(gpk);

            PackagesChanged?.Invoke();
            return(gpk);
        }
Esempio n. 2
0
        private void ServiceThread()
        {
            var endpoint  = new IPEndPoint(IPAddress.Any, 0);
            var checklist = new List <Socket>();

            udp.Client.Blocking = false;

            while (running)
            {
                checklist.Add(udp.Client);
                Socket.Select(checklist, null, null, 1000000); // 1 sec
                if (checklist.Count == 0)
                {
                    continue;
                }

                var packet = Encoding.UTF8.GetString(udp.Receive(ref endpoint));
                if (!packet.StartsWith("quack!"))
                {
                    continue;
                }
                var lines = new List <string>();
                foreach (var x in packet.Split('\n'))
                {
                    if (x.Trim().Length > 0)
                    {
                        lines.Add(x);
                    }
                }

                var cmd = lines[0].Split('!')[1];

                if (cmd == "packages-changed")
                {
                    var dist = lines[1].Split('/')[1];
                    var pkgs = new List <Tuple <string, uint?, string> >();

                    for (int i = 2; i < lines.Count; i++)
                    {
                        var s = lines[i].Split(':');
                        pkgs.Add(new Tuple <string, uint?, string>(s[0], Convert.ToUInt32(s[1]), null));
                    }

                    PackagesChanged?.Invoke(this, new ServiceMessageEventArgs(packet, dist, pkgs));
                }

                else if (cmd == "packages-available")
                {
                    string distro = null;
                    var    pkgs   = new List <Tuple <string, uint?, string> >();
                    for (int i = 1; i < lines.Count; i++)
                    {
                        if (lines[i].StartsWith("distro/"))
                        {
                            distro = lines[i].Split('/')[1];
                            continue;
                        }

                        var    s     = lines[i].Split(':');
                        uint?  rev   = null;
                        string group = null;

                        if (s[1] != "virtual")
                        {
                            rev = Convert.ToUInt32(s[1]);
                        }

                        if (s.Length > 2 && s[2].Length > 0)
                        {
                            group = s[2];
                        }

                        pkgs.Add(new Tuple <string, uint?, string>(s[0], rev, group));
                    }

                    AvailablePackagesAccepted?.Invoke(this, new ServiceMessageEventArgs(packet, distro, pkgs));
                }

                else if (cmd.StartsWith("dists-"))
                {
                    var dists = new List <string>();
                    for (int i = 1; i < lines.Count; i++)
                    {
                        dists.Add(lines[i]);
                    }

                    var e = new ServiceMessageEventArgs(packet, dists);
                    if (cmd == "dists-changed")
                    {
                        DistributionsChanged?.Invoke(this, e);
                    }
                    else
                    {
                        AvailableDistributionsAccepted?.Invoke(this, e);
                    }
                }

                else if (cmd == "text")
                {
                    string text = "";
                    for (int i = 1; i < lines.Count; i++)
                    {
                        text += lines[i] + "\n";
                    }

                    if (text.Length > 0)
                    {
                        text = text.Remove(text.Length - 1);
                        TextAccepted?.Invoke(this, new ServiceMessageEventArgs(packet, text));
                    }
                }

                else if (cmd == "wd")
                {
                    WorkingDirectory = lines[1];
                }

                else if (cmd == "index-changed")
                {
                    IndexChanged?.Invoke(this, new ServiceMessageEventArgs(packet));
                }

                else if (cmd == "action-update")
                {
                    ActionProgressUpdated?.Invoke(this, new ServiceMessageEventArgs(packet, lines[1], Convert.ToInt32(lines[2]), Convert.ToInt32(lines[3])));
                }

                else if (cmd == "action-complete")
                {
                    ActionComplete?.Invoke(this, new ServiceMessageEventArgs(packet, lines[1], 0, 0));
                }

                else if (cmd == "sources-changed")
                {
                    List <string> sources = new List <string>();
                    for (int x = 1; x < lines.Count; x++)
                    {
                        sources.Add(lines[x]);
                    }

                    SourcesChanged?.Invoke(this, new ServiceMessageEventArgs(packet, null, sources));
                }
            }

            udp.Close();
        }
Esempio n. 3
0
        public void clearGpkList()
        {
            LoadedGpkPackages.Clear();

            PackagesChanged?.Invoke();
        }
Esempio n. 4
0
        public void DeleteGpk(GpkPackage package)
        {
            LoadedGpkPackages.Remove(package);

            PackagesChanged?.Invoke();
        }