C# winform 批量修改后缀 批量加密解密 下载地址打乱和解析 多层自动解压(分卷压缩包也自动)文件向窗体拖拽 解压视图 游戏查找 指定某浏览器打开,预览 图片等等

添加文件(多选)下拉列表选择想要的后缀,后缀设置可排序 排序后 下拉列表按照顺序排列,可保存可删除 下拉列表可手动输入后缀点击修改时会保存输入的后缀

//数据
List<string> message = null;
//初始化窗体
private void 修改后缀_Load(object sender, EventArgs e)
{
    selectData();
    //默认下拉框 选中第一个预设值
    SuffixCb.SelectedIndex = 0;
}

private void selectData()
{
    SuffixCb.Items.Clear();
    // 查询后缀 并排序 升序
    message = SQLiteCode.SelectAll("SELECT suffixName FROM Suffix ORDER BY sort");
    foreach (var item in message)
    {
        SuffixCb.Items.Add(item);
    }
    //默认下拉框 选中第一个预设值
    SuffixCb.SelectedIndex = 0;
}

//创建 list集合 用于装多选路径
List<string> paths;
//添加压缩包
private void AddBt_Click(object sender, EventArgs e)
{
    //首先清空 预览
    OriginaName.Items.Clear();
    paths = PopupHelper.select_file(true, "请选择文件", "所有文件|*.*");

    foreach (var item in paths)
    {
        OriginaName.Items.Add(Path.GetFileName(item));
    }
    label2.Text = "已选:" + paths.Count;

}
//修改方法
private void UpdateBt_Click(object sender, EventArgs e)
{
    //去掉空格后判断 需要修改的后缀是否为空。
    //if (SuffixCb.Text.Trim() == "")
    //{
    //    //提示用户                
    //    MessageBox.Show("必须填写后缀", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    //    return;
    //}
    //如果 没选择文件就点修改 
    if (paths == null || paths.Count == 0)
    {
        MessageBox.Show("请先浏览添加文件", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        return;
    }
    Computer myCom = new Computer();
    //首先清空 预览 用于后续重新展示
    OriginaName.Items.Clear();
    //循环 多个路径 用于修改
    for (int i = 0; i < paths.Count; i++)
    {
        //按照顺序 取出路径
        string path = paths[i];
        //需要就修改成的  文件名+后缀
        string str = System.IO.Path.GetFileNameWithoutExtension(path) + "." + SuffixCb.Text;
        //尝试运行代码
        try
        {
            //如果选中的文件后缀 和 需要修改 的后缀 一致 
            //那么此方法会有异常,我们可以利用这个特性 来忽略 不需要修改的后缀
            myCom.FileSystem.RenameFile(path, str);
        }
        catch (Exception)//捕获异常
        {
            //即使出现跳过依然显示
            OriginaName.Items.Add(str);
            //异常捕获到了 说明 后缀一致 就重新循环
            continue;
        }
        //文件夹路径 + 文件名.后缀 修改后重新拼接 
        paths[i] = System.IO.Path.GetDirectoryName(path) + @"\" + str;
        //展示给 用户看
        OriginaName.Items.Add(str);
    }
    // 运行完毕给予提示
    MessageBox.Show("修改成功!");
}

private void SetupBt_Click(object sender, EventArgs e)
{
    selectData();
    Setup s = new Setup(message);
    s.ShowDialog();
    selectData();
}

加密解密(多文件)这块的进度条是真实的,真的。

//声明线程
Thread t = null;
public 加密解密()
{
    InitializeComponent();
    //阻止线程抛出异常
    Control.CheckForIllegalCrossThreadCalls = false;
    //默认选中 删除源文件
    DelectCB.Checked = true;
    //进度条 最大值
    progressBar1.Maximum = 100;
    //进度条 最小值 或者说从0开始
    progressBar1.Minimum = 0;
}
//存放完整路径
List<string> paths = null;
//添加文件
private void AddBt_Click(object sender, EventArgs e)
{
    paths = PopupHelper.select_file(true, "请选择文件", "全部文件|*.*");
    
    OriginalName.Items.Clear();

    foreach (string s in paths)
    {
        OriginalName.Items.Add(s);
    }
    //设置进度条为0
    progressBar1.Value = 0;
    //清空进度条标记
    this.label2.Text = "就绪";
}
//加密解密
private void EncryptionAndDecryptionBt_Click(object sender, EventArgs e)
{
    //判断 是否浏览选择文件
    if (paths == null)
    {
        MessageBox.Show("请先 浏览选择文件", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        return;
    }
    //每次开始进度条从0开始
    progressBar1.Value = 0;
    //初始化线程 并执行方法
    t = new Thread(new ThreadStart(EncryptionAndDecryption));
    //运行线程 启动 线程!!!
    t.Start();
    OriginalName.Items.Clear();
}
//线程执行的方法
private void EncryptionAndDecryption()
{
    for (int i = 0; i < paths.Count; i++)
    {
        //进度条标记 (i) 表示起始从0开始 paths.Count 表示用户选择的文件的最大数量
        this.label2.Text = (i) + "/" + paths.Count;
        //按照顺序 取出路径
        string path = paths[i];
        //创建文件流 
        FileStream read = null;
        try
        {
            //初始化 并打开
            read = new FileStream(paths[i], FileMode.Open);
        }
        catch (Exception)
        {
            MessageBox.Show("源文件已删除,请重新预览选择", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        //获取指定路径文件的 扩展名 如:.txt .rar .exe 等等
        string suffix = System.IO.Path.GetExtension(paths[i]);
        //返回指定路径文件的 文件名
        string name = System.IO.Path.GetFileNameWithoutExtension(paths[i]);
        //文件名中是否包含 XXX
        if (name.Contains("_已加密"))
        {
            //xxx 替换成 CCC + 后缀
            name = name.Replace("_已加密", "_解除") + suffix;
        }
        else if (name.Contains("_解除"))
        {
            name = name.Replace("_解除", "_已加密") + suffix;
        }
        else
        {
            name += "_已加密" + suffix;
        }
        //创建文件流
        FileStream write = new FileStream(System.IO.Path.GetDirectoryName(paths[i]) + @"\" + name, FileMode.Create);
        //声明 字节数组 用于 读取二进制数据
        byte[] bytes = new byte[1024000 * 5];//这里是控制每次读取的速度
        //标记
        int count = 0;
        //每次循环前 判断 字节数组里是否含有数据
        while ((count = read.Read(bytes, 0, bytes.Length)) > 0)
        {
            //二进制加密
            for (int j = 0; j < count; j++)
            {
                //用最大字节 减去 当前字节
                bytes[j] = (byte)(byte.MinValue - bytes[j]);
            }
            write.Write(bytes, 0, bytes.Length);
        }
        //上边 循环完1次 就是加密好一个文件
        //让进度条动起来
        progressBar1.Value += 100 / paths.Count;
        //进度条标记 1/7
        this.label2.Text = (i + 1) + "/" + paths.Count;
        //关闭读取流
        read.Dispose();
        //关闭写入流
        write.Dispose();
        //加密结束后 需要判断 是否删除源文件
        if (DelectCB.Checked)
        {
            try
            {
                //这个方法 如果文件被打开 那么会抛出异常
                File.Delete(paths[i]);
            }
            catch (Exception)
            {
                MessageBox.Show("源文件删除失败,正在被占用。", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        //修改后重新拼接 
        paths[i] = System.IO.Path.GetDirectoryName(path) + @"\" + name;
        string str = System.IO.Path.GetFileNameWithoutExtension(path) + "." + name;
        //展示给 用户看
        OriginalName.Items.Add(str);
    }
    progressBar1.Value = 100;
    MessageBox.Show("执行成功!");
    //关闭线程
    t.Abort();

 解析下载地址,现在屏蔽的厉害,分享链接也都穿插文字手动太麻烦,分享的时候选择下拉框预设(可输入可保存,就跟修改后缀一样不再介绍)汉字 会随机插入 并且 求关注谢谢 字的顺序不会颠倒。

 当点击还原时候 正则表达式 去掉 汉字,并且根据地址 补全 前缀 以下就是上方还原后的效果

    //数据
    List<string> message = null;
    public 下载地址解析()
    {
        InitializeComponent();
    }

    private void 解析下载地址_Load(object sender, EventArgs e)
    {
        selectData();
        //默认下拉框 选中第一个预设值
        insertCb.SelectedIndex = 0;
    }

    private void selectData()
    {

        insertCb.Items.Clear();
        // 查询后缀 并排序 升序
        message = SQLiteCode.SelectAll("SELECT insertText FROM Character ORDER BY sort");
        foreach (var item in message)
        {
            //向下拉列表 添加 插入的 字符串
            insertCb.Items.Add(item);
        }

        //默认下拉框 选中第一个预设值
        insertCb.SelectedIndex = 0;
    }
    //插入

    private void insertBt_Click(object sender, EventArgs e)
    {
        //初始化随机数
        Random rd = new Random();
        //从窗体拿到 地址
        string address = this.addressTb.Text.Trim();
        if (address.Length < 1 || address == "")
        {
            MessageBox.Show("地址还没输入呢,插不进去呀~", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        //用于存放地址
        List<string> listAddress = new List<string>();
        for (int i = 0; i < address.Length; i++)
        {
            //把字符串拆分成单个字符 放入list集合当中方便以后插入操作。
            listAddress.Add(address[i].ToString());
        }
        //从窗体拿到 需要插入的汉字 如:求关注谢谢
        string insert = this.insertCb.Text.Trim();

        //验证是否为空
        if (insert == "")
        {
            MessageBox.Show("请先 选择 或 输入 需要穿插的汉字", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        //验证是否包含除 汉字 以外的 字符
        for (int i = 0; i < insert.Length; i++)
        {
            if (!Regex.IsMatch(insert[i].ToString(), @"[\u4E00-\u9FA5]+$"))
            {
                MessageBox.Show("只能穿插汉字!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }


        //根据要插入的汉字的个数 获得对应的随机数
        List<int> listRandom = new List<int>();
        //根据要插入的汉字个数循环产生随机数
        for (int i = 0; i < insert.Length; i++)
        {
            //从1开始到地址长度范围 产生随机数
            listRandom.Add(rd.Next(1, address.Length));
        }
        //给随机数排序 升序
        listRandom.Sort();
        //根据要插入的汉字循环
        for (int i = 0; i < insert.Length; i++)
        {
            //用排序好的随机数 插入 地址的对应位置
            listAddress.Insert(listRandom[i], insert[i].ToString());
        }
        //临时存放
        string str = "";
        //插入后重新显示
        foreach (string item in listAddress)
        {
            str += item;
        }
        this.addressTb.Text = str;
    }
    //还原
    private void reductionBt_Click(object sender, EventArgs e)
    {
        //从窗体拿到 地址
        string address = this.addressTb.Text.Trim();

        //临时存放
        string str = "";
        //循环遍历地址中每一个字符
        for (int i = 0; i < address.Length; i++)
        {
            //利用 正则表达式验证是否为汉字
            if (Regex.IsMatch(address[i].ToString(), @"[\u4E00-\u9FA5]+$"))
            {
                //结果为true 那么就是汉字,从新循环
                continue;
            }
            else
            {
                //不是汉字就进行拼接

                str += address[i];


            }
        }
        //循环完毕后 判断是否为 无前缀
        //完整https://pan.baidu.com/s/1LoZCTR95LIZ76taBTtHtDw?pwd=qdmo
        //完整https://pan.baidu.com/s/1LoZCTR95LIZ76taBTtHtDw
        //1LoZCTR95LIZ76taBTtHtDw→23;1LoZCTR95LIZ76taBTtHtDw?pwd=qdmo→32
        if (str.Length == 23 || str.Length == 32)
        {
            str = "https://pan.baidu.com/s/" + str;
        }
        // /s/1Eza3ACxoE88_6dRGje0OHg→26;/s/1Eza3ACxoE88_6dRGje0OHg?pwd=qdmo
        else if (str.Length == 26 || str.Length == 35)
        {
            str = "https://pan.baidu.com" + str;
        }
        //夸克
        if (str.Length == 12)
        {
            str = "https://pan.quark.cn/s/" + str;
        }
        else if (str.Length == 15)
        {
            str = "https://pan.quark.cn" + str;
        }

        //重新显示到窗体中
        this.addressTb.Text = str;
    }


    //设置
    private void SetupBt_Click(object sender, EventArgs e)
    {
        selectData();
        Setup s = new Setup(message);
        s.ShowDialog();
        selectData();
    }

    private void saveBt_Click(object sender, EventArgs e)
    {
        //MessageBox.Show(insertCb.Text);
        //验证是否包含除 汉字 以外的 字符
        string insert = insertCb.Text.Trim();
        for (int i = 0; i < insert.Length; i++)
        {
            if (!Regex.IsMatch(insert[i].ToString(), @"[\u4E00-\u9FA5]+$"))
            {
                MessageBox.Show("只能穿插汉字!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
        if (insert != string.Empty)
        {
            SQLiteParameter[] paras = new SQLiteParameter[]
            {
                new SQLiteParameter("@insertText",insert),
                new SQLiteParameter("@sort",(message.Count+1))
            };
            int index = SQLiteCode.InsertPassWord("insert into Character (insertText,sort) values(@insertText,@sort)", paras);
            if (index == -100)
            {
                MessageBox.Show("该信息:" + this.insertCb.Text.Trim() + " 已存在", "请勿重复保存", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                insertCb.Text = string.Empty;
            }
            else if (index > 0)
            {
                selectData();
                //默认下拉框 选中第一个预设值
                insertCb.SelectedIndex = message.Count - 1;
                MessageBox.Show("保存成功");
            }
            else
            {
                MessageBox.Show("未知错误请联系 1020304", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //message
        }
        else
        {
            MessageBox.Show("需要插入的汉字不能为空", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

    }
}

 这个可以做到 自动解压 多层压缩包(包括 分卷)无视后缀是否正常,说实在的这个方法我琢磨了好久,我自信满满的想做成智能全自动特别智能的,但是我写着写着发现太难了尤其是分卷压缩,不可控因素太多了。所以我妥协了,解压位置必须是空的文件夹。。。原因是利用递归循环判断解压,如果这个文件夹里本身就有很多别的文件实在是不能判断……

 

List<string> file;
private void OriginaName_DragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
    {
        String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
        AddPathTb.Text = "";
        file = new List<string>();
        if (files.Length > 1)
        {
            MessageBox.Show("只能拖拽一个文件");
            return;
        }
        foreach (String s in files)
        {
            // (sender as ListBox).Items.Add(s);
            AddPathTb.Text = s;
            //AddPathTb.Text = Path.GetDirectoryName(s);
            file.Add(s);
        }
    }
}

private void OriginaName_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
        e.Effect = DragDropEffects.Link;
    else
        e.Effect = DragDropEffects.None;
}
//压缩包路径
private void AddPathBt_Click(object sender, EventArgs e)
{
    string s = "压缩包|*.RAR;*.ZIP;*.7Z;*.ARJ;*.BZ2;*.CAB;*.GZ;*.ISO;*.JAR;*.LZ;*.LZH;*.TAR;*.UUE;*.XZ;*.Z;*.ZST|";
    file = PopupHelper.select_file(false, "添加压缩包", s + "所有文件(*.*)|*.*");
    if (file.Count != 0)
    {
        AddPathTb.Text = "";
        AddPathTb.Text = file[0];
    }
}
//压缩包的输出“保存”绝对路径
private void SavePathBt_Click(object sender, EventArgs e)
{
    string file = PopupHelper.select_paper_file();
    if (file != string.Empty)
    {
        SavePathTb.Text = "";
        DirectoryInfo root = new DirectoryInfo(file);
        if (root.GetFiles().Length != 0 || root.GetDirectories().Length != 0)
        {
            MessageBox.Show("解压位置必须是空文件夹!!!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        SavePathTb.Text = file;
    }
}

List<string> pwds;
//开始解压
private void RunBt_Click(object sender, EventArgs e)
{
    //是否选择了 压缩包
    if (file == null || file.Count == 0)
    {
        MessageBox.Show("请先拖拽 或 浏览 选择文件!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        return;
    }
    //检查是否安装了RAR
    if (WinRarHelper.ExistsWinRar() == string.Empty)
    {
        MessageBox.Show("此方法需要安装 WinRAR", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        return;
    }
    //设置解压路径
    if (SavePathTb.Text == string.Empty)
    {
        MessageBox.Show("请选择解压到的位置", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        return;
    }
    //获得数据库 里存储的所有密码
    pwds = SQLiteCode.SelectAll("SELECT passWord FROM PassWord");
    //循环所有密码匹配解压
    if (!Run(SavePathTb.Text, AddPathTb.Text))
    {
        return;
    }

    SelectAll(SavePathTb.Text);
}
/// <summary>
/// 循环 尝试 解压
/// </summary>
/// <param name="savePath">解压后的路径</param>
/// <param name="addPathTb">压缩包的路径</param>
/// <param name="pwds">数据库中的密码</param>
/// <returns>false 失败</returns>
private bool Run(string savePath, string addPathTb)
{
    foreach (var pwd in pwds)
    {
        if (WinRarHelper.UnRarOrZip(savePath, addPathTb, pwd))
        {
            //静默解压
            if (!SilentCb.Checked)
            {
                MessageBox.Show("ok");
            }
            return true;
        }
    }
    MessageBox.Show("数据库中无此密码,请先将密码保存后再试", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    return false;
}

//递归所有 目录 和 子文件
private void SelectAll(string path)
{
    DirectoryInfo root = new DirectoryInfo(path);

    //当子目录文件夹 是1个继续 递归解压
    if (root.GetDirectories().Length > 1)
    {
        MessageBox.Show("彻底完毕");
        return;
    }
    //储存 文件夹中的 文件
    List<string> files = new List<string>();
    foreach (var item in root.GetFiles())
    {
        //字节 1024b = 1kb  1024kb = 1mb 1024 mb = 1GB 1024G = 1TB
        if (((item.Length / 1024) / 1024) > 5)
        {
            files.Add(item.FullName);
        }
    }
    //只有一个压缩包的时候
    if (files.Count == 1)
    {
        //目录信息
        string lujing = Path.GetDirectoryName(files[0]) + @"\";
        //文件名
        string name = Path.GetFileNameWithoutExtension(files[0]);
        //后缀
        //string 后缀 = Path.GetExtension(files[0]);
        //修改后缀
        Computer myCom = new Computer();

        try
        {
            //修改文件名 
            myCom.FileSystem.RenameFile(files[0], name + ".RAR");
            files[0] = lujing + name + ".RAR";
        }
        catch (System.Exception)//如果后缀名 相同抛出异常,重新循环
        {
        }

        if (!Run(path, files[0]))
        {
            return;
        }

    }
    //大于 2个文件 视作 分卷压缩包
    if (files.Count > 1)
    {
        string file = Decompression.Subsection(files);
        if (!Run(path, file))
        {
            return;
        }
    }
    //递归所有 子目录目录
    foreach (DirectoryInfo item in root.GetDirectories())
    {
        SelectAll(item.FullName);
    }
}
       

//密码设置
private void pwdBt_Click(object sender, EventArgs e)
{
    Setup s = new Setup(SQLiteCode.SelectAll("SELECT passWord FROM PassWord"));
    s.ShowDialog();
}
//保存密码
private void button1_Click(object sender, EventArgs e)
{
    if (this.pwbTb1.Text.Trim() != string.Empty)
    {
        SQLiteParameter[] paras = new SQLiteParameter[]
        {
        new SQLiteParameter("@passWord",this.pwbTb1.Text.Trim())
        };
        int index = SQLiteCode.InsertPassWord("insert into PassWord (passWord) values(@passWord)", paras);
        if (index == -100)
        {
            MessageBox.Show("该密码:" + this.pwbTb1.Text.Trim() + " 已存在", "请勿重复保存同样的密码", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            pwbTb1.Text = string.Empty;
        }
        else if (index > 0)
        {
            MessageBox.Show("保存成功");
            pwbTb1.Text = string.Empty;
        }
        else
        {
            MessageBox.Show("未知错误请联系 1020304", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
    else
    {
        MessageBox.Show("密码不能为空", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}

emmmmmmm接下来又是个老题,解压,上述解压是存在着问题的。如果是懂得人用不会出问题,就怕不懂得用户肯定会报错。。。所以它诞生了,,,没错我还给配了图片,至少看着得劲多了。点击浏览选择1个文件实际上取得是整个文件夹里所有文件,是的没错,之所以这样操作是因为Windows自带的那个选择文件夹窗体太难看了。。。。。

//浏览
private void button1_Click(object sender, EventArgs e)
{

    // 根据选择的文件 获得 父级 绝对路径
    string path = Path.GetDirectoryName(PopupHelper.select_file(true, "请选择文件", "所有文件|*.*")[0]);
    textBox1.Text = path;
    ShowListVile(path);
}

/// <summary>
/// 显示 listvile 文件夹 和 文件 
/// </summary>
/// <param name="path">需要显示的路径</param>
private void ShowListVile(string path)
{
    //首先清空 预览
    listView1.Items.Clear();
    //textBox1.Text = "";
    DirectoryInfo root = new DirectoryInfo(path);

    //遍历 目录  0代表目录的图片 1代表压缩包图片  2 代表文本  3 代表其他
    foreach (DirectoryInfo subFolder in root.GetDirectories())
    {
        listView1.Items.Add(new ListViewItem(new string[] { subFolder.Name, "文件夹", "-" }, 0));
    }

    //遍历文件
    foreach (FileInfo fileInfo in root.GetFiles())
    {
        string str = "未知";
        //图片索引
        int index = 1;
        switch (fileInfo.Extension)
        {
            case ".txt":
                str = "文本";
                break;
            case ".exe":
                str = "应用程序";
                break;
            case ".dll":
                str = "应用程序扩展";
                break;
            default:
                break;
        }
        listView1.Items.Add(new ListViewItem(new string[] { fileInfo.Name, str, fileInfo.Length + "" }, index));
    }
}

//存储选中多个 文件名
private List<String> names;
private void 解压ToolStripMenuItem_Click(object sender, EventArgs e)
{
    if (contextMenuStrip1.Items[0].Text == "打开")
    {
        string name = "";
        //获取选中 条数的 文件名
        ListView.SelectedIndexCollection SelectedIndexes = listView1.SelectedIndices;
        //循环 多文件 下标
        foreach (int Index in SelectedIndexes)
        {
            //根据下标获取文件名
            name = listView1.Items[Index].SubItems[0].Text;
        }
        textBox1.Text += @"\" + name;
        ShowListVile(textBox1.Text);
    }
    else
    {
        names = new List<string>();
        //获取选中 条数的 文件名
        ListView.SelectedIndexCollection SelectedIndexes = listView1.SelectedIndices;
        //循环 多文件 下标
        foreach (int Index in SelectedIndexes)
        {
            if (listView1.Items[Index].SubItems[1].Text == "文件夹")
            {
                MessageBox.Show("多条选项中包含了<文件夹>,无法分卷解压");
                return;
            }
            //根据下标获取文件名
            names.Add(listView1.Items[Index].SubItems[0].Text);
        }
        List<string> pwds = null;
        //根据 选中条数判断是否 分卷解压
        if (names.Count == 1)
        {
            //检查是否安装了RAR
            if (WinRarHelper.ExistsWinRar() == string.Empty)
            {
                MessageBox.Show("此方法需要安装 WinRAR", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //获得数据库 里存储的所有密码
            pwds = SQLiteCode.SelectAll("SELECT passWord FROM PassWord");
            foreach (var pwd in pwds)
            {
                if (WinRarHelper.UnRarOrZip(textBox1.Text, textBox1.Text +"\\"+ names[0], pwd))
                {
                    MessageBox.Show("ok");
                    //刷新显示
                    ShowListVile(textBox1.Text);
                    return;
                }
            }
        }
        else
        {
            //分卷解压
            foreach (string item in names)
            {
                MessageBox.Show(item);
            }
        }
    }
}
//打开当前文件夹
private void 打开所在文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
{
    try
    {
        Process.Start(textBox1.Text);
    }
    catch (Exception)
    {
        MessageBox.Show("当前文件夹不存在 或 路径错误");
    }
}
//右键菜单正在打开时 发生
private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
    //获取选中 条数的 文件名
    ListView.SelectedIndexCollection SelectedIndexes = listView1.SelectedIndices;

    if (SelectedIndexes.Count == 1)
    {
        if (listView1.Items[SelectedIndexes[0]].SubItems[1].Text == "文件夹")
        {
            contextMenuStrip1.Items[0].Text = "打开";
        }
        else
        {
            contextMenuStrip1.Items[0].Text = "解压";
        }
    }
    else
    {
        contextMenuStrip1.Items[0].Text = "解压";
    }

}
//目录后退
private void button3_Click(object sender, EventArgs e)
{
    try
    {
        textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.LastIndexOf("\\"));

        ShowListVile(textBox1.Text);
    }
    catch (Exception)
    {
        MessageBox.Show("孩子,你要后退到宇宙的起源么?", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}
//密码保存
private void button4_Click(object sender, EventArgs e)
{
    if (this.pwbTb1.Text.Trim() != string.Empty)
    {
        SQLiteParameter[] paras = new SQLiteParameter[]
        {
        new SQLiteParameter("@passWord",this.pwbTb1.Text.Trim())
        };
        int index = SQLiteCode.InsertPassWord("insert into PassWord (passWord) values(@passWord)", paras);
        if (index == -100)
        {
            MessageBox.Show("该密码:" + this.pwbTb1.Text.Trim() + " 已存在", "请勿重复保存同样的密码", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            pwbTb1.Text = string.Empty;
        }
        else if (index > 0)
        {
            MessageBox.Show("保存成功");
            pwbTb1.Text = string.Empty;
        }
        else
        {
            MessageBox.Show("未知错误请联系 1020304", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
    else
    {
        MessageBox.Show("密码不能为空", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}
//密码设置
private void pwdBt_Click(object sender, EventArgs e)
{
    Setup s = new Setup(SQLiteCode.SelectAll("SELECT passWord FROM PassWord"));
    s.ShowDialog();
}

 游戏查找。。。用的SQLite本地数据库。。

 添加游戏 下载地址 后台是真的去验证下。返回正常才通过。

 

 public GameSelect()
 {
     InitializeComponent();

     //浏览器默认选择  默认浏览器
     radioButton1.Checked = true;
 }
 //存放所有 游戏数据
 List<GameMessageClass> messages;
 //初始化加载方法
 private void GameSelect_Load(object sender, System.EventArgs e)
 {
     GameSelectLoad();
 }
 /// <summary>
 /// 刷新 只获得游戏 id 和 名字
 /// </summary>
 public void GameSelectLoad()
 {
     GameNameShow.Items.Clear();
     messages = new List<GameMessageClass>();
     DataSet ds = SQLiteCode.GetSelectAll("select id,name from GameMessage", null);
     Dictionary<string, int> gameMessage = new Dictionary<string, int>();
     if (ds != null && ds.Tables[0].Rows.Count > 0)
     {
         //循环 所有行
         for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
         {
             //主表 游戏表 中的 主键
             int game_id = int.Parse(ds.Tables[0].Rows[i]["id"].ToString());
             //游戏类的名字
             string name = ds.Tables[0].Rows[i]["name"].ToString();


             //把查询到的数据存储起来
             messages.Add(new GameMessageClass(game_id, name));
             //显示所有游戏名字
             GameNameShow.Items.Add(ds.Tables[0].Rows[i][1].ToString());
         }
     }
 }

 //游戏查询
 private void SelectGameBt_Click(object sender, System.EventArgs e)
 {
     GameSelectLoad();
     //获得 要查询的 文本
     string sel = this.selectTb.Text;
     //清空 listBox
     GameNameShow.Items.Clear();
     //循环所有 游戏
     foreach (var item in messages)
     {
         //游戏名 包含 要查询的 文本
         if (item.GetGameName.Contains(sel))
         {
             //显示出来
             GameNameShow.Items.Add(item.GetGameName);
         }
     }
 }

 //双击选中 游戏名 方法
 private void GameNameShow_DoubleClick(object sender, System.EventArgs e)
 {
     if (GameNameShow.SelectedIndex == -1)
     {
         return;
     }
     //清空集合

     //根据 双击 listBox 中的游戏名获得 下标 取出 游戏的所有数据
     gmc = messages[GameNameShow.SelectedIndex];
     this.groupBox3.Controls.Clear();
     //下载连接 
     GetAddres(gmc.GetGameID.ToString());
     //图片
     GetImage(gmc.GetGameID.ToString());
 }
 //声明图片集合
 List<PictureBox> pbs = null;
 /// <summary>
 /// 获取 游戏图片
 /// </summary>
 /// <param name="game_id">游戏主ID</param>
 private void GetImage(string game_id)
 {
     pbs = new List<PictureBox>();
     //通过 主表游戏表的 主键 查询 图片表
     SQLiteParameter[] paras = new SQLiteParameter[]
     {
         new SQLiteParameter("@game_id",game_id)
     };
     //List<ImgMessageClass> imgs = SQLiteCode.GetImgMessage("select id,width,height,ImageData from ImgMessage where id = @id", paras);
     DataSet ds = SQLiteHelper.GetDataTable("select game_id,imageName,ImageData from ImgMessage where game_id = @game_id", paras);
     for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
     {
         //PictureBox p = new PictureBox ();

         pbs.Add(new PictureBox());
     }
     //先清空控件
     panel1.Controls.Clear();
     //用来累计 高度
     int imgHeightSum = 0;
     if (ds != null && ds.Tables[0].Rows.Count > 0)
     {
         for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
         {
             imc = new List<ImgMessageClass>();
             imc.Add(new ImgMessageClass(0, ds.Tables[0].Rows[i]["imageName"].ToString(), ds.Tables[0].Rows[i]["ImageData"].ToString()));
             //取出图片
             pbs[i].Image = Image.FromStream(new MemoryStream((byte[])ds.Tables[0].Rows[i]["ImageData"]));

             int width = pbs[i].Image.Width;
             int height = pbs[i].Image.Height;
             //每次循环都需要判断这个图片的宽度是否超过控件大小需要做自适应缩放
             if (width <= 740)
             {
                 //说明是第一次循环 X Y 都是0
                 if (i == 0)
                 {
                     pbs[i].SetBounds(0, 0, width, height);
                 }
                 else
                 {
                     //不是第一次循环
                     imgHeightSum += pbs[i - 1].Image.Height;
                     pbs[i].SetBounds(0, imgHeightSum, width, height);
                 }
             }
             else
             {
                 //如果图片宽度大于 740
                 if (i == 0)
                 {
                     pbs[i].SetBounds(0, 0, 740, height);
                 }
                 else
                 {
                     imgHeightSum += pbs[i - 1].Image.Height;
                     pbs[i].SetBounds(0, imgHeightSum, 740, height);
                 }
                 //设置自适应
                 //pbs[i].SizeMode = PictureBoxSizeMode.StretchImage;

             }

             //缩放
             pbs[i].SizeMode = PictureBoxSizeMode.Zoom;
             //设置自适应 宽度过大 走样
             pbs[i].SizeMode = PictureBoxSizeMode.StretchImage;
             panel1.Controls.Add(pbs[i]);
         }
     }
 }

 /// <summary>
 /// 获取 下载连接地址
 /// </summary>
 /// <param name="game_id">游戏主id</param>
 private void GetAddres(string game_id)
 {
     //通过 主表游戏表的 主键 查询 图片表
     SQLiteParameter[] paras = new SQLiteParameter[]
     {
         new SQLiteParameter("@game_id",game_id)
     };
     //通过 主表游戏表的 主键ID 查询 下载地址表 
     addres = SQLiteCode.GetAddresMessage("select game_id,download,addres,extract,password from AddresMessage where game_id = @game_id", paras);

     foreach (var item in addres)
     {
         //创建 连接 button
         CreateButton(item);
     }
 }
 /// <summary>
 /// 动态创建按钮
 /// </summary>
 /// <param name="name">按钮的名字 以后操作用</param>
 /// <param name="text">展示名字</param>
 private void CreateButton(GameAddresMessage addres)
 {
     Button button = new Button();
     button.Size = new Size(85, 25);//Button大小
     int index = GetBtCount(this.groupBox3);
     button.Location = new Point((90 * index) + 5, 25);//位置
     button.Name = addres.GetGameAddres;
     button.Text = addres.GetGameDownload;
     button.Click += new EventHandler(btnEvent);//注册点击事件
     // button.ContextMenuStrip = DelSoftware;//绑定鼠标右键删除菜单


     this.groupBox3.Controls.Add(button);
     //解决 用代码创建的Button大小为什么不一样
     // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 20F);
     //this.AutoScaleDimensions = new System.Drawing.SizeF(10.5F, 20.1F);

     TextBox textBox = new TextBox();
     textBox.Size = new Size(85, 25);//Button大小

     textBox.Location = new Point((90 * index) + 5, 60);//位置

     textBox.Text = addres.GetGameExtract;
     this.groupBox3.Controls.Add(textBox);


     TextBox pwd = new TextBox();
     pwd.Size = new Size(85, 25);//Button大小

     pwd.Location = new Point((90 * index) + 5, 95);//位置

     pwd.Text = addres.GetGamePassword;
     this.groupBox3.Controls.Add(pwd);
 }
 //打开 浏览器 事件
 private void btnEvent(Object sender, EventArgs e)
 {

     //获取当前按钮
     Button button = (Button)sender;
     if (radioButton1.Checked == true)//默认浏览器
     {
         WebClass.OpenDefaultBrowserUrl(button.Name);
     }
     else if (radioButton2.Checked == true)//谷歌
     {
         WebClass.OpenBrowserUrl(button.Name);
     }
     else if (radioButton3.Checked == true)//火狐
     {
         WebClass.OpenFireFox(button.Name);
     }


     // MessageBox.Show(button.Name);
     //Web w = new Web(button.Name);
     //w.ShowDialog();
 }

 /// <summary>
 /// 获取 某个容器内有多少个 按钮 可以控制数量,也可以 作为间距控制
 /// </summary>
 /// <param name="panel">容器</param>
 /// <returns>几个按钮</returns>
 private int GetBtCount(Control panel)
 {
     int BtCount = 0;
     foreach (Control c in panel.Controls)
     {
         if (c is Button)
         {
             BtCount++;
         }
         BtCount += GetBtCount(c);
     }
     return BtCount;
 }
 //添加游戏
 private void addGame_Click(object sender, EventArgs e)
 {
     AddGame ag = new AddGame();
     ag.ShowDialog();
 }
 //当前选中的游戏类
 GameMessageClass gmc;
 //地址 修改时候用
 List<GameAddresMessage> addres;
 //当前选中的 游戏图片
 List<ImgMessageClass> imc;
 //修改游戏
 private void updateGame_Click(object sender, EventArgs e)
 {
     if (GameNameShow.SelectedIndex == -1)
     {
         MessageBox.Show("必须先双击 游戏名字 才能修改的游戏!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
     if (gmc != null && addres != null && imc != null)
     {
         UpdateGame ug = new UpdateGame(gmc, addres, imc);
         ug.ShowDialog();
     }
 }

 检查网址是否能正确打开

public static bool IsValidUrl(string url)
{
    try
    {
        var request = WebRequest.Create(url);
        request.Timeout = 5000;
        request.Method = "HEAD";

        using (var response = (HttpWebResponse)request.GetResponse())
        {
            response.Close();
            return response.StatusCode == HttpStatusCode.OK;
        }
    }
    catch (Exception exception)
    {
        return false;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值