📄 packer.cs
字号:
//
this.llCopy.Location = new System.Drawing.Point(10, 276);
this.llCopy.Name = "llCopy";
this.llCopy.Size = new System.Drawing.Size(67, 17);
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, ((byte)(0)));
this.bLoad.Location = new System.Drawing.Point(106, 459);
this.bLoad.Name = "bLoad";
this.bLoad.Size = new System.Drawing.Size(90, 24);
this.bLoad.TabIndex = 1;
this.bLoad.Text = "&Load";
this.bLoad.UseVisualStyleBackColor = false;
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, ((byte)(0)));
this.bSave.Location = new System.Drawing.Point(202, 459);
this.bSave.Name = "bSave";
this.bSave.Size = new System.Drawing.Size(90, 24);
this.bSave.TabIndex = 1;
this.bSave.Text = "&Save";
this.bSave.UseVisualStyleBackColor = false;
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, ((byte)(0)));
this.bClear.Location = new System.Drawing.Point(298, 459);
this.bClear.Name = "bClear";
this.bClear.Size = new System.Drawing.Size(90, 24);
this.bClear.TabIndex = 1;
this.bClear.Text = "&Clear";
this.bClear.UseVisualStyleBackColor = false;
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(6, 14);
this.CancelButton = this.bClear;
this.ClientSize = new System.Drawing.Size(716, 543);
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.Name = "Packer";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Packer";
this.Load += new System.EventHandler(this.Packer_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#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 + -