Esempio n. 1
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();
        }
Esempio 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);
                        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();
        }