public Byte[] resourceInfoToBytes(ResourceInfo[] resInfoList) { StringBuilder sb = new StringBuilder(); int i = 0; int c = resInfoList.Length; while (i < c) { ResourceInfo resInfo = resInfoList[i]; sb.Append(resInfo.name); sb.Append(","); sb.Append(resInfo.version); sb.Append(","); sb.Append(Convert.ToString(resInfo.bytesTotal)); sb.Append("\r\n"); i++; } if (resInfoList.Length != 0) sb.Remove(sb.Length - 2, 2); Byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString()); return bytes; }
static private String readFromSqlite(String path, ArrayList list) { //Pooling设置为true时,SQL连接将从连接池获得,如果没有则新建并添加到连接池中,默认是true。 //FailIfMissing默认为false,如果数据库文件不存在,会自动创建一个新的,若设置为true,将不会创建,而是抛出异常信息。 SQLiteConnection conn = new SQLiteConnection("Data Source=" + path + ".svn/wc.db;Pooling=true;FailIfMissing=true"); //try { conn.Open(); } //catch (Exception e) //{ // MessageBox.Show("打开数据文件失败\r\n" + path); //} SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; DataSet dataset = new DataSet(); SQLiteDataAdapter sd = new SQLiteDataAdapter(cmd); //=====列出所有的表用于查看====== //cmd.CommandText = "SELECT * FROM [sqlite_master] where [type] = 'table'"; //sd.Fill(dataset, "tables"); //DataTable tables = dataset.Tables["tables"]; //foreach (DataRow row in tables.Rows) //{ // cmd.CommandText = "SELECT * FROM [" + row["name"] + "]"; // sd.Fill(dataset, row["name"].ToString()); //} //========================== //读取数据 //获取主版本号 cmd.CommandText = "SELECT * FROM [NODES] where ([local_relpath] = '' or [local_relpath] is null) and ([parent_relpath] = '' or [parent_relpath] is null)"; sd.Fill(dataset, "buildVersion"); DataTable buildVersion = dataset.Tables["buildVersion"]; //cmd.CommandText = "SELECT * FROM [NODES] where [kind] = 'file' and [presence] = 'normal' and [translated_size] is not null"; cmd.CommandText = "SELECT * FROM [NODES] where [kind] = 'file' and [presence] = 'normal'"; //cmd.CommandText = "SELECT * FROM [NODES]"; sd.Fill(dataset, "versions"); DataTable versions = dataset.Tables["versions"]; foreach (DataRow row in versions.Rows) { ResourceInfo resInfo = new ResourceInfo(); resInfo.name = row["local_relpath"].ToString(); resInfo.version = row["changed_revision"].ToString(); try { resInfo.bytesTotal = (long)row["translated_size"]; list.Add(resInfo); } catch (Exception) { Console.WriteLine("获取文件svn信息失败:\r\n" + resInfo.name); } } conn.Close(); return buildVersion.Rows[0]["revision"].ToString(); }
/// <summary> /// 1.6及之前版本解析算法 /// 已知问题:对于某些曾经删除的文件解析不正确导致导出时缺少该文件信息 /// </summary> /// <param name="path_baseFolder"></param> /// <param name="path_subFolder"></param> /// <param name="list"></param> static private void doMakeCfg(String path_baseFolder, String path_subFolder, ArrayList list) { String path_folder = path_baseFolder + "/" + path_subFolder; String path_svnEntries = path_folder + "/" + path_entries; if (File.Exists(path_svnEntries)) { DirectoryInfo di = new DirectoryInfo(path_folder); Byte[] ba = FileUtil.readFile(path_svnEntries); String entries = Encoding.UTF8.GetString(ba); Regex reg = new Regex(@"[^\f\n\r\t\v]+\s+file\s+[\s\S]+?\s+\d+\s+[^\f\n\r\t\v]+"); Regex reg_file = new Regex(@"^[^\f\n\r\t\v]+"); Regex reg_version = new Regex(@"\s+(\d+)\s+[^\f\n\r\t\v]+$"); MatchCollection mc = reg.Matches(entries); foreach (Match mh in mc) { String str = mh.Value; Match mh_ver = reg_version.Match(str); String file = reg_file.Match(str).Value; String ver = mh_ver.Groups[1].Value; FileInfo fi = new FileInfo(path_folder + "/" + file); if (!fi.Exists) continue; ResourceInfo fc = new ResourceInfo(); fc.name = path_subFolder + "/" + file; if (fc.name[0] == '/') fc.name = fc.name.Substring(1, fc.name.Length - 1); fc.version = ver; fc.bytesTotal = fi.Length; list.Add(fc); } //枚举子目录进行递归查找 DirectoryInfo[] list_di = di.GetDirectories(); foreach (DirectoryInfo subDi in list_di) { doMakeCfg(path_baseFolder, path_subFolder + "/" + subDi.Name, list); } } }