public static ZIPFile WriteToArchive(this SolutionBuilder that)
		{
			var zip = new ZIPFile();

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

			return zip;
		}
		// 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());
		}
Ejemplo n.º 3
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);
		}
Ejemplo n.º 4
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);
            }
        }
        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();
        }
        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();
        }
Ejemplo n.º 7
0
 public static void Add(this ZIPFile z, string FileName, XElement value)
 {
     z.Add(FileName, value.ToString());
 }
        public void Handler(WebServiceHandler h)
        {
            // http://dev.opera.com/articles/view/opera-extensions-hello-world/
            // http://dev.opera.com/articles/view/converting-widgets-to-opera-extensions/
            // http://zproxy.wordpress.com/2009/09/01/windows-forms-inside-opera-widget/
            // http://dev.opera.com/articles/view/opera-extensions-buttons-badges-and-popups/


            if (h.Context.Request.Path == "/foo.oex"
                || h.Context.Request.Path == "/foo.zip")
            {
                // what? how many implementations does jsc have? 3
                //var a = new ZIPArchive();

                h.Context.Response.ContentType = "application/octet-stream";

                var a = new ZIPFile();

                a.Add("readme.txt", "hello world " + DateTime.Now);

                // http://dev.opera.com/articles/view/extensions-api-toolbar-createitem/

//                #region index.html
//                a.Add("index.html",
//@"
//
//<html lang='en'>
//  <head>
//    <script>
//        window.addEventListener('load', function () {
//            var theButton;
//            var ToolbarUIItemProperties = {
//                title: 'Hello World',
//                icon: 'assets/ScriptCoreLib/jsc.png',
//                popup: {
//                    href: 'popup.html',
//                    width: 410,
//                    height: 430
//                }
//            }
//            theButton = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
//            opera.contexts.toolbar.addItem(theButton);
//        }, false);
//    </script>
//  </head>
//  <body>
//  </body>
//</html>
//"
//                );
//                #endregion

                // http://dev.opera.com/articles/view/extensions-api-windows-tabs/
                // http://dev.opera.com/articles/view/extensions-api-windows-create/
                // http://dev.opera.com/articles/view/opera-extensions-developer-workflow/
                h.Applications.Single().With(
                    app =>
                    {

                        var popup = XElement.Parse(app.PageSource);
                        var placeholder = "/* script */";

                        var script = new XElement("script", placeholder);

                        //                        [12/15/2012 5:57:52 PM] JavaScript - widget://wuid-4edc9dae-900c-8740-9e83-ff032877d339/popup.html
                        //Inline script compilation
                        //Syntax error at line 364 while loading: expected ')', got ';'
                        //    while (!(f &lt; 0))
                        //------------------^


                        var w = new StringBuilder();
                        app.References.WithEach(
                            r =>
                            {
                                var path = h.Context.Request.MapPath("/" + r.AssemblyFile + ".js");

                                w.Append(
                                    File.ReadAllText(path)
                                );
                            }
                        );

                        popup.Add(script);

                        var xml = popup.ToString();

                        xml = xml.Replace(placeholder, w.ToString());

                        #region popup.html
                        //a.Add("popup.html", xml);
                        a.Add("index.html", xml);
                        #endregion
                    }
                );

                #region config.xml
                a.Add("config.xml",
                   @"
<?xml version='1.0' encoding='UTF-8'?>
<widget xmlns = 'http://www.w3.org/ns/widgets' network='public'>
<feature name='opera:screenshot' required='false'/>

  <name>OperaExtensionExperiment</name>
  <description>OperaExtensionExperiment description</description>

  <author>
    <name>foo bar</name>
    <email>[email protected]</email>
    <link>http://example.com</link>
    <organization></organization>
  </author>
  
</widget>

"
                );
                #endregion


                MemoryStream m = a;

                m.WriteTo(h.Context.Response.OutputStream);


                h.CompleteRequest();
                return;
            }
        }
        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
                };


        }
Ejemplo n.º 10
0
 public static ZIPFile WriteToFile(this ZIPFile that, FileInfo f)
 {
     File.WriteAllBytes(f.FullName, that.ToBytes());
     return(that);
 }
Ejemplo n.º 11
0
		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();
							}
						);
					}

				};

		}