Example #1
0
        static void Main(string[] args)
        {
            var crc = new Crc32Helper();

            crc.ComputeCrc32(new byte[] { 1, 2, 0xfe, 0xff });

            // Crc32Value = 0x3d414fa9

            var z = new ZIPFile
            {
                { "default.txt", "hello world" }
            };

            var m = z.ToBytes();

            var w = new StringBuilder();

            var xxi = 0;

            foreach (var xx in m)
            {
                xxi++;
                w.Append(" " + xx.ToString("x2"));
                if ((xxi % 16) == 0)
                {
                    w.AppendLine();
                }
            }

            Console.WriteLine(w.ToString());

            /*
             * flash
             * 50 4b 03 04 0a 00 00 00 00 00 80 5c fa 3a 16 ff
             * ff ff 0b 00 00 00 0b 00 00 00 0b 00 00 00 64 65
             * 66 61 75 6c 74 2e 74 78 74 50 4b 01 02 14 00 0a
             * 00 00 00 00 00 80 5c fa 3a 95 2e 51 ff 29 00 00
             * 00 29 00 00 00 0b 00 00 00 00 00 00 00 00 00 00
             * 00 00 00 00 00 00 00 64 65 66 61 75 6c 74 2e 74
             * 78 74 50 4b 05 06 00 00 00 00 01 00 01 00 39 00
             * 00 00 29 00 00 00 00 00
             *
             * .net
             * 50 4b 03 04 0a 00 00 00 00 00 fd 5c fa 3a 85 11
             * 4a 0d 0b 00 00 00 0b 00 00 00 0b 00 00 00 64 65
             * 66 61 75 6c 74 2e 74 78 74 68 65 6c 6c 6f 20 77
             * 6f 72 6c 64 50 4b 01 02 14 00 0a 00 00 00 00 00
             * fd 5c fa 3a 85 11 4a 0d 0b 00 00 00 0b 00 00 00
             * 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
             * 00 00 64 65 66 61 75 6c 74 2e 74 78 74 50 4b 05
             * 06 00 00 00 00 01 00 01 00 39 00 00 00 34 00 00
             * 00 00 00
             *
             *
             */

            File.WriteAllBytes("archive2.zip", m);
        }
        public static ZIPFile WriteToArchive(this SolutionBuilder that)
        {
            var zip = new ZIPFile();

            that.WriteTo(
                f => zip.Add(f.Name, f.Content)
                );

            return(zip);
        }
 public static void ToBitmapArray(this ZIPFile zip, Bitmap[] cache, Action <Bitmap[]> h)
 {
     if (cache == null)
     {
         zip.ToBitmapArray(h);
     }
     else
     {
         h(cache);
     }
 }
 public static void ToBitmapArray(this ZIPFile zip, Action <int, int> progress, Bitmap[] cache, Action <Bitmap[]> h)
 {
     if (cache == null)
     {
         zip.ToBitmapArray(progress, h);
     }
     else
     {
         h(cache);
     }
 }
        private static byte[] GetContent()
        {
            var z = new ZIPFile();

            var c = 0;

            foreach (Tag k in new MemcacheCollection {
                ElementType = typeof(Tag)
            })
            {
                c++;
                z.Add("file-" + c + ".txt", k.PathAndQuery);
            }

            return(z.ToBytes());
        }
        public static void ToBitmapDictionary(this ZIPFile zip, Action <Dictionary <string, Bitmap> > handler)
        {
            var Keys = zip.Items.Select(k => k.FileName).ToArray();

            zip.Items.Select(k => k.Data).ToImages(
                e =>
            {
                var n = new Dictionary <string, Bitmap>();

                e.ForEach((v, i) => n.Add(Keys[i], v));


                handler(n);
            }
                );
        }
        private byte[] GetContent()
        {
            var z = new ZIPFile
            {
                { "default1.txt", "hello" },
                { "default2.txt", "world" },
                { "task1.zip",
                  new ZIPFile
                  {
                      { "default3.txt", "cool" },
                      { "ken/default4.txt", "huh" },
                  } }
            };


            return(z.ToBytes());
        }
        private static void DownloadJavaZip(WebServiceHandler h, string TypesList)
        {
            var Types = TypesList.Split(',');
            var zip   = new ZIPFile();

            foreach (var item in Types)
            {
                var w = new StringBuilder();



                var p = new global::Bulldog.Server.CodeGenerators.Java.DefinitionProvider(
                    item,
                    new WebClient().DownloadString
                    )
                {
                    Server = "www.jsc-solutions.net"
                };

                zip.Add(
                    item.Replace(".", "/") + ".cs",
                    p.GetString()
                    );
            }

            // http://www.ietf.org/rfc/rfc2183.txt

            h.Context.Response.ContentType = ZIPFile.ContentType;

            h.Context.Response.AddHeader(
                "Content-Disposition",
                "attachment; filename=" + TypesList + ".zip"
                );


            var bytes = zip.ToBytes();

            h.Context.Response.OutputStream.Write(bytes, 0, bytes.Length);

            h.CompleteRequest();
        }
 public static void ToBitmapArray(this ZIPFile zip, Action <Bitmap[]> handler)
 {
     zip.Items.Select(k => k.Data).ToImages(handler);
 }
        // to be used only on .net

        public static void WriteToConsole(this SolutionBuilder that)
        {
            var Lookup = new Dictionary <SolutionFileTextFragment, ConsoleColor>
            {
                { SolutionFileTextFragment.Comment, ConsoleColor.Green },
                { SolutionFileTextFragment.Keyword, ConsoleColor.Cyan },

                { SolutionFileTextFragment.None, ConsoleColor.Gray },

                { SolutionFileTextFragment.String, ConsoleColor.Red },
                { SolutionFileTextFragment.XMLAttributeName, ConsoleColor.Red },
                { SolutionFileTextFragment.XMLAttributeValue, ConsoleColor.Blue },
                { SolutionFileTextFragment.XMLComment, ConsoleColor.Green },
                { SolutionFileTextFragment.XMLKeyword, ConsoleColor.Blue },
                { SolutionFileTextFragment.Type, ConsoleColor.Yellow },
            };

            var zip = new ZIPFile();

            that.WriteTo(
                SolutionFile =>
            {
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(" " + SolutionFile.Name + " ");

                //if (SolutionFile.WriteHistory.Count > 1)
                foreach (var item in SolutionFile.WriteHistory)
                {
                    if (item.Fragment == SolutionFileTextFragment.Indent)
                    {
                        Console.BackgroundColor = ConsoleColor.DarkGray;
                    }
                    else if (item.Fragment == SolutionFileTextFragment.XMLText)
                    {
                        Console.BackgroundColor = ConsoleColor.DarkCyan;
                    }
                    else
                    {
                        Console.BackgroundColor = ConsoleColor.Black;
                    }

                    if (Lookup.ContainsKey(item.Fragment))
                    {
                        Console.ForegroundColor = Lookup[item.Fragment];
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    Console.Write(item.Text);
                }

                Console.WriteLine();

                zip.Add(SolutionFile.Name, SolutionFile.Content);
            }
                );

            var Output = new FileInfo(that.Name).FullName + ".zip";

            Console.WriteLine(Output);
            File.WriteAllBytes(Output, zip.ToBytes());
        }
        public CachedFileGenerator(CachedFileGeneratorBase.Arguments Arguments, bool UnqualifiedEnvironment = false)
            : base(Arguments)
        {
            // http://stackoverflow.com/questions/867485/c-getting-the-path-of-appdata
            // http://support.microsoft.com/kb/2600217#UpdateReplacement

            var CommonApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            var Version = Environment.Version.ToString();

            if (UnqualifiedEnvironment)
            {
                Version = Version.TakeUntilLastIfAny(".");
            }

            var CacheFolder = new DirectoryInfo(
                Path.Combine(
                    CommonApplicationData,
                    "jsc/"
                    + "cache/"
                    + Version
                    + "/"
                    + this.ConstructorArguments.AssamblyFile.Name
                    + "/"
                    + this.ConstructorArguments.Language.ToString()
                    )
                );


            // next new cache name
            var Cache = new FileInfo(
                Path.Combine(
                    CacheFolder.FullName,
                    this.ConstructorArguments.AssamblyFile.Name + ".zip"
                    )
                );


            this.AtValidate +=
                delegate
            {
                // time to extract the zip file if ready and emit the local token

                if (Cache.Exists)
                {
                    // great. now compare the times

                    if (this.ConstructorArguments.AssamblyFile.LastWriteTime > Cache.LastWriteTime)
                    {
                        // no dice. the target is newer than our cache.

                        Cache.Delete();
                        Cache.Refresh();
                    }
                }

                if (Cache.Exists)
                {
                    //Debugger.Launch();

                    var zip = Cache.ToZIPFile();

                    foreach (var item in zip.Entries)
                    {
                        var FilePath = Path.Combine(
                            this.ConstructorArguments.TargetDirectory.FullName,
                            item.FileName
                            );

                        this.Add(
                            FilePath,
                            item.Text
                            );
                    }

                    this.WriteLocalTokens();
                    this.WriteLocalFiles();
                }
                else
                {
                    if (this.SourceVersion.Exists)
                    {
                        this.SourceVersion.Delete();
                    }

                    CacheFolder.Create();
                    CacheFolder.Clear();
                }
            };

            this.AtWriteTokens +=
                delegate
            {
                // if the cache still exists it's time to write the zip file

                //Console.WriteLine("CachedFileGenerator AtWriteTokens" + new { Cache.Exists });

                if (Cache.Exists)
                {
                    return;
                }

                CacheFolder.Create();
                CacheFolder.Clear();

                var zip = new ZIPFile();

                foreach (var item in this.Files)
                {
                    var RelativeFileName = item.FileName.Replace("\\", "/").SkipUntilIfAny(this.ConstructorArguments.TargetDirectory.FullName.Replace("\\", "/") + "/");

                    //Console.WriteLine("CachedFileGenerator AtWriteTokens" + new { RelativeFileName });

                    zip.Add(RelativeFileName, item.Content);
                }

                // should we mark NTFS it compressable?

                //Debugger.Launch();



                zip.WriteToFile(Cache);


                #region SDK
                if (this.SDK != null)
                {
                    var SDKCacheFolder = new DirectoryInfo(
                        Path.Combine(
                            SDK.FullName,
                            "cache/"
                            + Version
                            + "/"
                            + this.ConstructorArguments.AssamblyFile.Name
                            + "/"
                            + this.ConstructorArguments.Language.ToString()
                            )
                        );


                    SDKCacheFolder.Create();
                    SDKCacheFolder.Clear();
                    var SDKCache = new FileInfo(
                        Path.Combine(
                            SDKCacheFolder.FullName,
                            this.ConstructorArguments.AssamblyFile.Name + ".zip"
                            )
                        );


                    zip.WriteToFile(SDKCache);
                }
                #endregion
            };
        }
        private static void DownloadJavaZip(WebServiceHandler h, string TypesList)
        {
            var Types = TypesList.Split(',');
            var zip = new ZIPFile();

            foreach (var item in Types)
            {
                var w = new StringBuilder();



                var p = new global::Bulldog.Server.CodeGenerators.Java.DefinitionProvider(
                    item,
                    new WebClient().DownloadString
                )
                {
                    Server = "www.jsc-solutions.net"
                };

                zip.Add(
                    item.Replace(".", "/") + ".cs",
                    p.GetString()
                );
            }

            // http://www.ietf.org/rfc/rfc2183.txt

            h.Context.Response.ContentType = ZIPFile.ContentType;

            h.Context.Response.AddHeader(
                "Content-Disposition",
                "attachment; filename=" + TypesList + ".zip"
            );


            var bytes = zip.ToBytes();

            h.Context.Response.OutputStream.Write(bytes, 0, bytes.Length);

            h.CompleteRequest();
        }
 public void Clear()
 {
     this.zip = new ZIPFile();
 }
        public OrcasAvalonApplicationCanvas()
        {
            Width  = DefaultWidth;
            Height = DefaultHeight;

            this.ClipToBounds = true;

            Colors.Blue.ToGradient(Colors.Red, DefaultHeight / 4).Select(
                (c, i) =>
                new Rectangle
            {
                Fill   = new SolidColorBrush(c),
                Width  = DefaultWidth,
                Height = 4,
            }.MoveTo(0, i * 4).AttachTo(this)
                ).ToArray();


            var help_idle = new Image
            {
                Source = (KnownAssets.Path.Assets + "/help_idle.png").ToSource()
            }.AttachTo(this);

            var help = new Image
            {
                Source = (KnownAssets.Path.Assets + "/help.png").ToSource()
            }.AttachTo(this);

            help.Opacity = 0;

            var img = new Image
            {
                Source = (KnownAssets.Path.Assets + "/jsc.png").ToSource()
            }.MoveTo(DefaultWidth - 128, DefaultHeight - 128).AttachTo(this);

            (1000 / 30).AtIntervalWithCounter(
                c =>
            {
                img.MoveTo(DefaultWidth - 128, DefaultHeight - 128
                           + Math.Sin(c * 0.1) * 4
                           );
            }
                );

            var t = new TextBox
            {
                AcceptsReturn   = true,
                FontSize        = 10,
                Text            = "powered by jsc",
                BorderThickness = new Thickness(0),
                Foreground      = Brushes.Blue,
                Background      = Brushes.White,
                IsReadOnly      = true,
                Width           = 400,
                Height          = 400
            }.MoveTo(32, 32).AttachTo(this);



            var cc = 0;

            this.MouseLeftButtonUp +=
                delegate
            {
                cc++;

                if (cc % 2 == 1)
                {
                    t.Text = "saving...";

                    var r = new FileDialog();

                    var z = new ZIPFile
                    {
                        { "default.txt", "hello world" },
                        { "readme.txt", "this was created in flash via c#" }
                    };

                    var m = z.ToBytes();

                    r.Save(new MemoryStream(m), "archive1.zip");

                    var w = new StringBuilder();


                    var xxi = 0;
                    foreach (var xx in m)
                    {
                        xxi++;
                        w.Append(" " + xx.ToString("x2"));
                        if ((xxi % 16) == 0)
                        {
                            w.AppendLine();
                        }
                    }

                    t.Text = w.ToString();
                }
                else
                {
                    t.Text = "loading...";

                    var r = new FileDialog();

                    r.Open(
                        m =>
                    {
                        m.Position = 0;

                        ZIPFile z = m;
                        var w     = new StringBuilder();

                        foreach (var zf in z.Entries)
                        {
                            w.AppendLine(zf.FileName);

                            var xxi = 0;
                            foreach (var xx in zf.Bytes)
                            {
                                xxi++;
                                w.Append(" " + xx.ToString("x2"));
                                if ((xxi % 16) == 0)
                                {
                                    w.AppendLine();
                                }
                            }
                            w.AppendLine();
                            w.AppendLine(zf.Text);
                        }

                        t.Text = w.ToString();
                    }
                        );
                }
            };
        }
Example #15
0
        public static void TransformRobocode()
        {
            var w = new Uri("http://robocode.sourceforge.net/docs/robocode/allclasses-noframe.html").ToWebString();

            var zip = new ZIPFile();

            var o = 0;

            while (o >= 0)
            {
                const string pregfix = "<A HREF=\"";
                var          i       = w.IndexOf(pregfix, o);
                if (i >= 0)
                {
                    var j = w.IndexOf("\"", i + pregfix.Length);

                    if (j >= 0)
                    {
                        var type = w.Substring(i + pregfix.Length, j - (i + pregfix.Length));

                        const string suffix = ".html";

                        if (type.EndsWith(suffix))
                        {
                            o = j + 1;

                            type = type.Substring(0, type.Length - suffix.Length).Replace("/", ".");

                            Console.WriteLine(type);


                            zip.Add(type.Replace(".", "/") + ".cs",
                                    new DefinitionProvider(
                                        type
                                        //        "robocode.BattleRules"
                                        //        //"java.net.InetSocketAddress"
                                        //        //"java.net.ServerSocket"
                                        //        //"java.nio.channels.ServerSocketChannel"
                                        , k => k.ToWebString()).GetString()
                                    );
                        }
                        else
                        {
                            o = -1;
                        }
                    }
                    else
                    {
                        o = -1;
                    }
                }
                else
                {
                    o = -1;
                }
            }

            using (var ww = new BinaryWriter(File.OpenWrite("Robocode.zip")))
            {
                zip.WriteTo(ww);
            }
        }