批量下载辅助工具

qq旋风下载批量生成任务不是很完善,批量任务时必须把任务地址输入,必须复制多次。因此写了个小程序,辅助生成这些要下载的地址。

 项目文件下载http://files.cnblogs.com/hbhzz/MultiText.rar

前台代码

 

namespace MultiText
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox_source = new System.Windows.Forms.TextBox();
            this.textBox_key = new System.Windows.Forms.TextBox();
            this.textBox_start = new System.Windows.Forms.TextBox();
            this.textBox_end = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.textBox_show = new System.Windows.Forms.TextBox();
            this.button_create = new System.Windows.Forms.Button();
            this.button_copy = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // textBox_source
            //
            this.textBox_source.Location = new System.Drawing.Point(1, 12);
            this.textBox_source.Multiline = true;
            this.textBox_source.Name = "textBox_source";
            this.textBox_source.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBox_source.Size = new System.Drawing.Size(546, 55);
            this.textBox_source.TabIndex = 0;
            //
            // textBox_key
            //
            this.textBox_key.Location = new System.Drawing.Point(71, 86);
            this.textBox_key.Name = "textBox_key";
            this.textBox_key.Size = new System.Drawing.Size(100, 21);
            this.textBox_key.TabIndex = 1;
            //
            // textBox_start
            //
            this.textBox_start.Location = new System.Drawing.Point(229, 73);
            this.textBox_start.Name = "textBox_start";
            this.textBox_start.Size = new System.Drawing.Size(77, 21);
            this.textBox_start.TabIndex = 1;
            //
            // textBox_end
            //
            this.textBox_end.Location = new System.Drawing.Point(229, 99);
            this.textBox_end.Name = "textBox_end";
            this.textBox_end.Size = new System.Drawing.Size(77, 21);
            this.textBox_end.TabIndex = 1;
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(209, 95);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(17, 12);
            this.label1.TabIndex = 2;
            this.label1.Text = "至";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(12, 89);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(53, 12);
            this.label2.TabIndex = 2;
            this.label2.Text = "要替换的";
            //
            // textBox_show
            //
            this.textBox_show.Location = new System.Drawing.Point(1, 126);
            this.textBox_show.Multiline = true;
            this.textBox_show.Name = "textBox_show";
            this.textBox_show.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBox_show.Size = new System.Drawing.Size(546, 247);
            this.textBox_show.TabIndex = 0;
            //
            // button_create
            //
            this.button_create.Location = new System.Drawing.Point(364, 72);
            this.button_create.Name = "button_create";
            this.button_create.Size = new System.Drawing.Size(75, 47);
            this.button_create.TabIndex = 3;
            this.button_create.Text = "生成";
            this.button_create.UseVisualStyleBackColor = true;
            this.button_create.Click += new System.EventHandler(this.button_create_Click);
            //
            // button_copy
            //
            this.button_copy.Location = new System.Drawing.Point(445, 72);
            this.button_copy.Name = "button_copy";
            this.button_copy.Size = new System.Drawing.Size(75, 47);
            this.button_copy.TabIndex = 3;
            this.button_copy.Text = "复制";
            this.button_copy.UseVisualStyleBackColor = true;
            this.button_copy.Click += new System.EventHandler(this.button_copy_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.ActiveBorder;
            this.ClientSize = new System.Drawing.Size(548, 385);
            this.Controls.Add(this.button_copy);
            this.Controls.Add(this.button_create);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.textBox_end);
            this.Controls.Add(this.textBox_start);
            this.Controls.Add(this.textBox_key);
            this.Controls.Add(this.textBox_show);
            this.Controls.Add(this.textBox_source);
            this.Name = "Form1";
            this.Text = "批量地址生成";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox textBox_source;
        private System.Windows.Forms.TextBox textBox_key;
        private System.Windows.Forms.TextBox textBox_start;
        private System.Windows.Forms.TextBox textBox_end;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox_show;
        private System.Windows.Forms.Button button_create;
        private System.Windows.Forms.Button button_copy;
    }
}

后台代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MultiText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button_create_Click(object sender, EventArgs e)
        {

           //如果没有填写第一个那么不进行操作

            if (textBox_source.Text.Trim()=="")
            {
                return;
            }

     
            string source = textBox_source.Text.Trim();

    //如果用string则每次需要创建新的变量,重新分配内存,量大的情况下会使效率下来,因此用stringbuilder

            StringBuilder strBuider = new StringBuilder();

          //默认是从1到10
            int start = 1;
            int end = 10;

       //可以手动设置例如 http://www.******/03.zip至 20.zip

            if (textBox_start.Text.Trim() != "" && textBox_end.Text.Trim() != "")
            {
                start = int.Parse(textBox_start.Text.Trim());
                end = int.Parse(textBox_end.Text.Trim());
            }

    //设置链接中要替换的字符。如果不提供则默认是倒数第一个‘.’前边两位作为置换字符串

            string key = "";

            if (textBox_key.Text != "")
            {
                key = textBox_key.Text;
            }
            else
            {
               key= source.Substring(source.LastIndexOf('.') - 2, 2);
            }
            string tmpI = "";

            for (int i = start; i <= end; i++)
            {
                if (i < 10)
                {
                    tmpI = "0" + i;
                }
                else
                {
                    tmpI = i.ToString();
                }
                source.Replace(key,tmpI);
                strBuider.Append(source.Replace(key, tmpI)+" ");
               
            }

          //展示到结果列表中

            textBox_show.Text = strBuider.ToString();

        }
        //点击复制按钮,复制到剪切板,就可以放到旋风中了

        private void button_copy_Click(object sender, EventArgs e)
        {
           // Clipboard.SetText();这个方法会报错,可能必须复制结构化的文本吧


            Clipboard.SetDataObject(textBox_show.Text);
        }
    }
}

原文地址:https://www.cnblogs.com/hbhzz/p/3174685.html