Ejemplo n.º 1
0
        private void AddRepo(string url, string srchdir = "", bool defaultrep = false, string decloc = "")
        {
            if (!url.EndsWith("/"))
            {
                url += "/";
            }
            Repo r = new Repo(url, RefreshProgress, srchdir, decloc);

            foreach (Repo rep in repos)
            {
                if (rep.name == r.name)
                {
                    return;
                }
            }
            if (r.packages != null && r.name != null)
            {
                r.defaultsource = defaultrep;
                repos.Add(r);
            }
            if (r != null && r.name != null)
            {
                string path     = Environment.CurrentDirectory + "/" + r.name + "/";
                string dataname = path + "data.repodata";
                ObjectSaver.WriteToXmlFile(dataname, r);

                //Fix for coolstar's weird description
                string orig = File.ReadAllText(dataname);
                Helper.RemoveSpecialCharacters(orig);
                File.Delete(dataname);
                File.WriteAllText(dataname, orig);


                string          zipname = r.name.Replace('/', '.') + ".repo";
                ZipOutputStream zip     = new ZipOutputStream(File.Create(zipname));

                string folderName = r.name;

                int folderOffset = folderName.Length + (folderName.EndsWith("\\") ? 0 : 1);

                Helper.CompressFolder(folderName, zip, folderOffset);

                zip.IsStreamOwner = true;
                zip.Close();
            }
        }
Ejemplo n.º 2
0
        private void ReloadRepos()
        {
            SplashScreen splash = new SplashScreen();

            splash.Show();
            splash.Select();

            RepoBox.ClearSelected();
            Packages.ClearSelected();

            rep   = new Repo();
            boxes = new Dictionary <string, CheckedListBox>();
            repos = new List <Repo>();

            selected = new Dictionary <string, Package>();
            string[] repofiles = Directory.GetFiles(Environment.CurrentDirectory, "*.repo");
            Parallel.ForEach(repofiles, (r) => {
                bool cont     = false;
                FileStream fs = File.OpenRead(r);
                ZipFile zf    = new ZipFile(fs);

                string path = zf.Name.Replace(".repo", "");

                foreach (ZipEntry zipEntry in zf)
                {
                    try {
                        string name = zipEntry.Name;

                        byte[] buffer    = new byte[4096];
                        Stream zipStream = zf.GetInputStream(zipEntry);

                        String fullZipToPath = Path.Combine(path, name);

                        string directoryName = Path.GetDirectoryName(fullZipToPath);
                        if (directoryName.Length > 0)
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        using (FileStream streamWriter = File.Create(fullZipToPath)) {
                            StreamUtils.Copy(zipStream, streamWriter, buffer);
                        }
                    } catch (DirectoryNotFoundException ex) {
                        Console.WriteLine(ex.Message);
                        cont = true;
                        break;
                    } catch (FileNotFoundException ex) {
                        Console.WriteLine(ex.Message);
                        cont = true;
                        break;
                    }
                }
                if (cont)
                {
                    return;
                }
                string n         = zf.Name;
                zf.IsStreamOwner = true;
                zf.Close();

                try {
                    string data = path + "/data.repodata";
                    Repo toadd  = ObjectSaver.ReadFromXmlFile <Repo>(data);
                    if (toadd.version < reversion)
                    {
                        toadd = new Repo(toadd.url, new ProgressBar(), toadd.srchdir, toadd.debloc);
                    }
                    else if (toadd.version > reversion)
                    {
                        DialogResult answer = MessageBox.Show("Colliding versions", toadd.name + " has been installed using a higher version of RepositoryExplorer. Do you want to update the repo to the new version? Answering no might lead to unexpected behaviour", MessageBoxButtons.YesNo);
                        if (answer == DialogResult.Yes)
                        {
                            toadd = new Repo(toadd.url, new ProgressBar(), toadd.srchdir, toadd.debloc);
                        }
                    }
                    toadd.selected = new List <Package>();
                    toadd.sel      = new List <Package>();
                    repos.Add(toadd);

                    CheckedListBox b = new CheckedListBox();
                    foreach (Package pak in toadd.packages.Values)
                    {
                        b.Items.Add(pak);
                    }
                    boxes.Add(toadd.name, b);
                } catch (FileNotFoundException ex) {
                    File.Delete(n);
                    Console.WriteLine(ex.Message);
                    return;
                }
                Directory.Delete(path, true);
            });
            ReloadRepoBox();

            splash.Hide();
            splash.Close();
            this.Show();
            this.Select();
        }
Ejemplo n.º 3
0
        private void ReloadRepos()
        {
            SplashScreen splash = new SplashScreen();

            splash.Show();
            splash.Select();
            RepoBox.ClearSelected();
            Packages.ClearSelected();

            rep      = new Repo();
            boxes    = new Dictionary <string, CheckedListBox>();
            repos    = new List <Repo>();
            selected = new Dictionary <string, Package>();
            string[] repofiles = Directory.GetFiles(Environment.CurrentDirectory, "*.repo");
            Parallel.ForEach(repofiles, (r) => {
                bool cont     = false;
                FileStream fs = File.OpenRead(r);
                ZipFile zf    = new ZipFile(fs);

                string path = zf.Name.Replace(".repo", "");

                foreach (ZipEntry zipEntry in zf)
                {
                    try {
                        string name = zipEntry.Name;

                        byte[] buffer    = new byte[4096];
                        Stream zipStream = zf.GetInputStream(zipEntry);

                        String fullZipToPath = Path.Combine(path, name);
                        Console.WriteLine(fullZipToPath);

                        string directoryName = Path.GetDirectoryName(fullZipToPath);
                        if (directoryName.Length > 0)
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        using (FileStream streamWriter = File.Create(fullZipToPath)) {
                            StreamUtils.Copy(zipStream, streamWriter, buffer);
                        }
                    } catch (DirectoryNotFoundException ex) {
                        Console.WriteLine(ex.Message);
                        cont = true;
                        break;
                    } catch (FileNotFoundException ex) {
                        Console.WriteLine(ex.Message);
                        cont = true;
                        break;
                    }
                }
                if (cont)
                {
                    return;
                }
                string n         = zf.Name;
                zf.IsStreamOwner = true;
                zf.Close();

                try {
                    string data    = path + "/data.repodata";
                    Repo toadd     = ObjectSaver.ReadFromXmlFile <Repo>(data);
                    toadd.selected = new List <Package>();
                    toadd.sel      = new List <Package>();
                    repos.Add(toadd);

                    CheckedListBox b = new CheckedListBox();
                    foreach (Package pak in toadd.packages.Values)
                    {
                        b.Items.Add(pak);
                    }
                    boxes.Add(toadd.name, b);
                } catch (FileNotFoundException ex) {
                    File.Delete(n);
                    Console.WriteLine(ex.Message);
                    return;
                }
                Directory.Delete(path, true);
            });
            ReloadRepoBox();

            splash.Hide();
            splash.Close();
            this.Show();
            this.Select();
        }