比这篇新的文章: RGB颜色值转HTML十六进制(HEX)代码的JS函数
比这篇旧的文章: 惹人

更新Firefox Addon版本号的主程序

语言: C#, 标签: Firefox 2008/07/21发布 1年前更新
作者: 半瓶墨水, 点击915次, 评论(0), 收藏者(0), , 打分:

背景
主题: 字体:
01 //Firefox更新以后许多Addon不能用,实际上有些Addon是可以用的,比如TabMixPlus其实也能用在3.0.1
02 //所以就写了这个程序来更改Addon自己设置的限定来暂时使用
03 //过两天写成比较通用的tool再放程序出来,这里是临时写的程序的主要部分
04 using System;
05 using System.Collections.Generic;
06 using System.ComponentModel;
07 using System.Data;
08 using System.Drawing;
09 using System.Linq;
10 using System.Text;
11 using System.Windows.Forms;
12 using System.IO;
13 using System.Xml;
14 using System.Text.RegularExpressions;
15 using System.Collections;
16
17 namespace FirefoxExtFakeUpdate
18 {
19     public partial class Main : Form
20     {
21         public Main()
22         {
23             InitializeComponent();
24         }
25
26         private void btnUpdate_Click(object sender, EventArgs e)
27         {
28             //update all the install.rdf files that is selected
29             for (int i=0; i<listExts.Items.Count; i++)
30             {
31                 if (listExts.GetItemChecked(i))
32                 {
33                     string filePath = rdfPaths[i];
34                     string text = File.ReadAllText(filePath);
35                     string ver = GetFirefoxCurrentVersion();
36                     Regex rx = new Regex("<em:maxVersion>(.*)</em:maxVersion>", RegexOptions.IgnoreCase);
37                     text = rx.Replace(text, "<em:maxVersion>" + ver + "</em:maxVersion>");
38                     rx = new Regex("em:maxVersion=\"(.*)\"", RegexOptions.IgnoreCase);
39                     text = rx.Replace(text, "em:maxVersion=\"" + ver + "\"");
40                     File.SetAttributes(filePath, FileAttributes.Normal);
41                     File.WriteAllText(filePath, text);
42                 }
43             }
44         }
45
46         private string GetFirefoxCurrentVersion()
47         {
48             string ffIni = @"C:\Program Files\Mozilla Firefox\application.ini";
49             string text = File.ReadAllText(ffIni);
50             Regex rx = new Regex("Version=(.*)", RegexOptions.IgnoreCase);
51             return rx.Match(text).Groups[1].Value;
52         }
53
54         private List<string> rdfPaths = new List<string>();
55
56         private void Main_Load(object sender, EventArgs e)
57         {
58             string ver = GetFirefoxCurrentVersion();
59             lblFirefoxVersion.Text = "您的Firefox版本:" + ver;
60             //load all the extensions
61             string path = @"C:\Documents and Settings\zhren\Application Data\Mozilla\Firefox\Profiles\rd2ffv7d.default\extensions\";
62             string[] dirs = Directory.GetDirectories(path);
63             foreach (string dir in dirs) {
64                 string filePath = dir + "\\install.rdf";
65                 if (!File.Exists(filePath)) continue;
66                 string text = File.ReadAllText(filePath);
67                 Regex rx = new Regex("<em:name>(.*)</em:name>", RegexOptions.IgnoreCase);
68                 string name = rx.Match(text).Groups[1].Value;
69                 if (name.Length == 0) {
70                     rx = new Regex("em:name=\"(.*)\"", RegexOptions.IgnoreCase);
71                     name = rx.Match(text).Groups[1].Value;
72                 }
73                 rx = new Regex("<em:maxVersion>(.*)</em:maxVersion>", RegexOptions.IgnoreCase);
74                 string maxVersion = rx.Match(text).Groups[1].Value;
75                 if (maxVersion.Length == 0)
76                 {
77                     rx = new Regex("em:maxVersion=\"(.*)\"", RegexOptions.IgnoreCase);
78                     maxVersion = rx.Match(text).Groups[1].Value;
79                 }
80                 listExts.Items.Add(name + "(" + maxVersion + ")", true);
81                 rdfPaths.Add(filePath);
82             }
83         }
84     }
85 }


所有评论,共0条:( 我也来说两句)


发表评论

注册登录后再发表评论