예제 #1
0
        private void AddCompressorDecorator(CompressionAlgs algorithms)
        {
            List <ICompression> baseCompressors = new List <ICompression>(algorithms.objects);

            foreach (ICompression compressor in baseCompressors)
            {
                algorithms.objects.Add(new CipherDecorator(compressor));
            }
        }
예제 #2
0
        private List <Star> OpenCompressedWorld()
        {
            timerMove.Stop();

            List <Star>     stars      = new List <Star>();
            CompressionAlgs algorithms = new CompressionAlgs(pluginPath);

            if (algorithms.objects.Count == 0)
            {
                MessageBox.Show("No plugins");
                return(stars);
            }

            OpenFileDialog dlg = new OpenFileDialog();

            string filter = string.Empty;

            foreach (ICompressor alg in algorithms.objects)
            {
                filter += "*" + alg.Format + ";";
            }
            filter     = filter.TrimEnd(';');
            dlg.Filter = "Archives (" + filter + ")|" + filter;

            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                try
                {
                    string ext  = System.IO.Path.GetExtension(dlg.FileName);
                    string temp = dlg.FileName.Replace(ext, "");

                    ICompressor compressor = algorithms.objects.Find(obj => obj.Format == ext.ToLower());
                    compressor.Decompress(dlg.FileName, temp);

                    stars = DeserializeWorld(temp);

                    File.Delete(temp);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error");
                    return(stars);
                }

                foreach (Star star in stars)
                {
                    star.Show(canvasModel);
                }
            }

            timerMove.Start();

            return(stars);
        }
예제 #3
0
        private void btnCompress_Click(object sender, EventArgs e)
        {
            time.Stop();
            NewSerializer  newSerializer = new NewSerializer();
            SaveFileDialog dlg           = new SaveFileDialog();

            dlg.FileName = "World";

            CompressionAlgs algorithms = new CompressionAlgs(pluginPath);

            if (algorithms.objects.Count == 0)
            {
                MessageBox.Show("No plugins");
                return;
            }

            AddCompressorDecorator(algorithms);

            string filter = string.Empty;

            foreach (ICompression alg in algorithms.objects)
            {
                filter += alg.Name + " archive (*" + alg.Format + ")|*" + alg.Format + "|";
            }
            dlg.Filter = filter.TrimEnd('|');

            bool result = dlg.ShowDialog() == DialogResult.OK;

            if (result == true)
            {
                BinarySerialization bin  = new BinarySerialization();
                XmlSerialization    xml  = new XmlSerialization();
                TextSerialization   text = new TextSerialization();

                string       ext        = Path.GetExtension(dlg.FileName);
                string       name       = dlg.FileName.Replace(ext, "");
                ICompression compressor = algorithms.objects.Find(obj => obj.Format == ext);

                xml.Serialize(star, name + ".xml");
                compressor.Compress(name + ".xml", name + ".xml" + ext);
                File.Delete(name + ".xml");

                bin.Serialize(star, name + ".bin");
                compressor.Compress(name + ".bin", name + ".bin" + ext);
                File.Delete(name + ".bin");

                text.Serialize(star, name + ".txt");
                compressor.Compress(name + ".txt", name + ".txt" + ext);
                File.Delete(name + ".txt");
            }
            time.Start();
        }
예제 #4
0
        private void btnDecompress_Click(object sender, EventArgs e)
        {
            time.Stop();
            NewSerializer newSerializer = new NewSerializer();

            CompressionAlgs algorithms = new CompressionAlgs(pluginPath);

            if (algorithms.objects.Count == 0)
            {
                MessageBox.Show("No plugins");
            }

            AddCompressorDecorator(algorithms);

            OpenFileDialog dlg = new OpenFileDialog();

            string filter = string.Empty;

            foreach (ICompression alg in algorithms.objects)
            {
                filter += "*" + alg.Format + ";";
            }
            filter     = filter.TrimEnd(';');
            dlg.Filter = "Archives (" + filter + ")|" + filter;

            bool result = dlg.ShowDialog() == DialogResult.OK;

            if (result == true)
            {
                try
                {
                    string ext  = System.IO.Path.GetExtension(dlg.FileName);
                    string temp = dlg.FileName.Replace(ext, "");

                    ICompression compressor = algorithms.objects.Find(obj => obj.Format == ext);
                    compressor.Decompress(dlg.FileName, temp);

                    star = (Star)newSerializer.GetfileName_Serialization(dlg.FileName).Deserialize(typeof(Star), temp);

                    File.Delete(temp);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error");
                }
            }

            time.Start();
        }
예제 #5
0
        private void SaveCompressedWorld()
        {
            timerMove.Stop();

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName = "World";

            CompressionAlgs algorithms = new CompressionAlgs(pluginPath);

            if (algorithms.objects.Count == 0)
            {
                MessageBox.Show("No plugins");
                return;
            }

            string filter = string.Empty;

            foreach (ICompressor alg in algorithms.objects)
            {
                filter += alg.Name + " archive (*" + alg.Format + ")|*" + alg.Format + "|";
            }
            dlg.Filter = filter.TrimEnd('|');

            bool?result = dlg.ShowDialog();

            if (result == true)
            {
                string      ext        = System.IO.Path.GetExtension(dlg.FileName);
                string      name       = dlg.FileName.Replace(ext, "");
                ICompressor compressor = algorithms.objects.Find(obj => obj.Format == ext.ToLower());

                Serializer.XmlSerialize(stars, name + ".xml");
                compressor.Compress(name + ".xml", name + ".xml" + ext);
                File.Delete(name + ".xml");

                Serializer.BinarySerialize(stars, name + ".bin");
                compressor.Compress(name + ".bin", name + ".bin" + ext);
                File.Delete(name + ".bin");

                Serializer.JsonSerialize(stars, name + ".json");
                compressor.Compress(name + ".json", name + ".json" + ext);
                File.Delete(name + ".json");
            }

            timerMove.Start();
        }