⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 packer.cs

📁 JavaScript 压缩工具 使用 C# 开发
💻 CS
📖 第 1 页 / 共 2 页
字号:
            this.llPaste.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llPaste_LinkClicked);
            // 
            // llCopy
            // 
            this.llCopy.Location = new System.Drawing.Point(8, 256);
            this.llCopy.Name = "llCopy";
            this.llCopy.Size = new System.Drawing.Size(56, 16);
            this.llCopy.TabIndex = 4;
            this.llCopy.TabStop = true;
            this.llCopy.Text = "Copy:";
            this.llCopy.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llCopy_LinkClicked);
            // 
            // bLoad
            // 
            this.bLoad.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.bLoad.BackColor = System.Drawing.Color.LightSkyBlue;
            this.bLoad.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.bLoad.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.bLoad.Location = new System.Drawing.Point(88, 490);
            this.bLoad.Name = "bLoad";
            this.bLoad.TabIndex = 1;
            this.bLoad.Text = "&Load";
            this.bLoad.Click += new System.EventHandler(this.bLoad_Click);
            // 
            // bSave
            // 
            this.bSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.bSave.BackColor = System.Drawing.Color.LightSkyBlue;
            this.bSave.Enabled = false;
            this.bSave.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.bSave.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.bSave.Location = new System.Drawing.Point(168, 490);
            this.bSave.Name = "bSave";
            this.bSave.TabIndex = 1;
            this.bSave.Text = "&Save";
            this.bSave.Click += new System.EventHandler(this.bSave_Click);
            // 
            // bClear
            // 
            this.bClear.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.bClear.BackColor = System.Drawing.Color.LightSkyBlue;
            this.bClear.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.bClear.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.bClear.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.bClear.Location = new System.Drawing.Point(248, 490);
            this.bClear.Name = "bClear";
            this.bClear.TabIndex = 1;
            this.bClear.Text = "&Clear";
            this.bClear.Click += new System.EventHandler(this.bClear_Click);
            // 
            // ofdSource
            // 
            this.ofdSource.DefaultExt = "js";
            this.ofdSource.Filter = "ECMAScript Files|*.js|All files|*.*";
            this.ofdSource.Title = "Choose a file";
            // 
            // sfdResult
            // 
            this.sfdResult.DefaultExt = "js";
            this.sfdResult.Filter = "ECMAScript Files|*.js|All files|*.*";
            // 
            // Packer
            // 
            this.AcceptButton = this.pack;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.bClear;
            this.ClientSize = new System.Drawing.Size(794, 568);
            this.Controls.Add(this.llPaste);
            this.Controls.Add(this.fastDecode);
            this.Controls.Add(this.Encoding);
            this.Controls.Add(this.pack);
            this.Controls.Add(this.tbSource);
            this.Controls.Add(this.tbResult);
            this.Controls.Add(this.specialChars);
            this.Controls.Add(this.llCopy);
            this.Controls.Add(this.bLoad);
            this.Controls.Add(this.bSave);
            this.Controls.Add(this.bClear);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Name = "Packer";
            this.Text = "Packer";
            this.Load += new System.EventHandler(this.Packer_Load);
            this.ResumeLayout(false);

        }
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Packer());
		}

        private void pack_Click(object sender, System.EventArgs e)
        {
            ECMAScriptPacker p = new ECMAScriptPacker((ECMAScriptPacker.PackerEncoding) Encoding.SelectedItem, fastDecode.Checked, specialChars.Checked);
            tbResult.Text = p.Pack(tbSource.Text).Replace("\n", "\r\n");
            bSave.Enabled = true;
        }

        private void Packer_Load(object sender, System.EventArgs e)
        {
            Encoding.Items.Add(ECMAScriptPacker.PackerEncoding.None);
            Encoding.Items.Add(ECMAScriptPacker.PackerEncoding.Numeric);
            Encoding.Items.Add(ECMAScriptPacker.PackerEncoding.Mid);
            Encoding.Items.Add(ECMAScriptPacker.PackerEncoding.Normal);
            Encoding.Items.Add(ECMAScriptPacker.PackerEncoding.HighAscii);
            Encoding.SelectedItem = ECMAScriptPacker.PackerEncoding.Normal;
        }

        private void Encoding_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            fastDecode.Enabled = ((ECMAScriptPacker.PackerEncoding)Encoding.SelectedItem != ECMAScriptPacker.PackerEncoding.None);
        }

        private void llPaste_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            tbSource.Text = (string)Clipboard.GetDataObject().GetData(typeof(string));
        }

        private void llCopy_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            Clipboard.SetDataObject(tbResult.Text, true);
        }

        private void bClear_Click(object sender, System.EventArgs e)
        {
            tbResult.Text = tbSource.Text = string.Empty;
            bSave.Enabled = false;
        }

        private void bLoad_Click(object sender, System.EventArgs e)
        {
            DialogResult r = ofdSource.ShowDialog(this);
            if (r == DialogResult.OK)
            {
                Stream s = ofdSource.OpenFile();
                TextReader rd = new StreamReader(s);
                string content = rd.ReadToEnd();
                rd.Close();
                s.Close();
                Regex regex = new Regex("([^\r])(\n+)");
                tbSource.Text = regex.Replace(content, new MatchEvaluator(changeUnixLineEndings));
            }
        }

        private string changeUnixLineEndings(Match match)
        {
            return match.Value.Replace("\n", "\r\n");
        }

        private void bSave_Click(object sender, System.EventArgs e)
        {
            DialogResult r = sfdResult.ShowDialog(this);
            if (r == DialogResult.OK)
            {
                Stream s = sfdResult.OpenFile();
                TextWriter rd = new StreamWriter(s);
                rd.Write(tbResult.Text);
                rd.Close();
                s.Close();
            }
        }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -