JAD生成方法
1
2 /// <summary>
3 /// JAR文件直接生成JAD文件包
4 /// </summary>
5 /// <param name="jarfilePath"></param>
6 private void BuildJad( string jarfilePath)
7 {
8 string lineStr = "" ;
9 if ( ! File.Exists(jarfilePath)) return ;
10 if (jarfilePath.ToLower().IndexOf( " .jar " ) < 0 ) return ;
11
12 var fileInfo = new FileInfo(jarfilePath);
13 var stringBuilder = new StringBuilder( " MIDlet-Jar-Size: " );
14 stringBuilder.Append(fileInfo.Length);
15 stringBuilder.Append( " \r\n " );
16 stringBuilder.Append( " MIDlet-Jar-URL: " );
17 stringBuilder.Append(fileInfo.Name);
18 stringBuilder.Append( " \r\n " );
19
20 string jadFilePath = jarfilePath.Remove(jarfilePath.LastIndexOf( ' . ' )) + " .jad " ;
21
22 // 保存jad,dirCach为保存的jad路径
23 string cachePath = @" E:\temp " + DateTime.Now.ToString( " yyyy " ) + @" \ " + DateTime.Now.ToString( " MM " ) + @" \ " +
24 DateTime.Now.ToString( " dd " );
25
26 if ( ! Directory.Exists(cachePath))
27 Directory.CreateDirectory(cachePath);
28
29 DecompressRar(jarfilePath, cachePath);
30 var sr = new StreamReader(cachePath + " \\META-INF\\MANIFEST.MF " );
31 while ((lineStr = sr.ReadLine()) != null )
32 {
33 stringBuilder.Append(lineStr).Append( " \r\n " );
34 }
35 sr.Close();
36
37 // 删除解开的数据
38 Directory.Delete(cachePath, true );
39 if (File.Exists(jadFilePath))
40 {
41 // 备份数据
42 string pathBak = fileInfo.DirectoryName.ToLower().Replace( " uploads " , " uploadsBakJad " );
43 if ( ! Directory.Exists(pathBak))
44 Directory.CreateDirectory(pathBak);
45 File.Delete(jadFilePath.ToLower().Replace( " uploads " , " uploadsBakJad " ));
46 File.Move(jadFilePath, jadFilePath.ToLower().Replace( " uploads " , " uploadsBakJad " ));
47 }
48 StreamWriter wr = File.CreateText(jadFilePath);
49 wr.Write(stringBuilder);
50 wr.Close();
51 log.Info( " file " + jarfilePath + " is ok " );
52 }
53
54 private static void DecompressRar( string rarFileToDecompress, string directoryToSave)
55 {
56 string winrarExe = ConfigurationManager.AppSettings[ " winrarExepath " ];
57 if ( new FileInfo(winrarExe).Exists)
58 {
59 try
60 {
61 Process p = new Process();
62 // 需要启动的程序名
63 p.StartInfo.FileName = winrarExe;
64 // 参数
65 string arguments = @" x -inul -y -o+ " ;
66 arguments += " " + rarFileToDecompress + " " + directoryToSave;
67 p.StartInfo.Arguments = arguments;
68 p.Start(); // 启动
69 while ( ! p.HasExited)
70 { }
71 p.WaitForExit();
72 }
73 catch (Exception ee)
74 {
75 throw new Exception(ee.Message);
76 }
77 }
78 }
2 /// <summary>
3 /// JAR文件直接生成JAD文件包
4 /// </summary>
5 /// <param name="jarfilePath"></param>
6 private void BuildJad( string jarfilePath)
7 {
8 string lineStr = "" ;
9 if ( ! File.Exists(jarfilePath)) return ;
10 if (jarfilePath.ToLower().IndexOf( " .jar " ) < 0 ) return ;
11
12 var fileInfo = new FileInfo(jarfilePath);
13 var stringBuilder = new StringBuilder( " MIDlet-Jar-Size: " );
14 stringBuilder.Append(fileInfo.Length);
15 stringBuilder.Append( " \r\n " );
16 stringBuilder.Append( " MIDlet-Jar-URL: " );
17 stringBuilder.Append(fileInfo.Name);
18 stringBuilder.Append( " \r\n " );
19
20 string jadFilePath = jarfilePath.Remove(jarfilePath.LastIndexOf( ' . ' )) + " .jad " ;
21
22 // 保存jad,dirCach为保存的jad路径
23 string cachePath = @" E:\temp " + DateTime.Now.ToString( " yyyy " ) + @" \ " + DateTime.Now.ToString( " MM " ) + @" \ " +
24 DateTime.Now.ToString( " dd " );
25
26 if ( ! Directory.Exists(cachePath))
27 Directory.CreateDirectory(cachePath);
28
29 DecompressRar(jarfilePath, cachePath);
30 var sr = new StreamReader(cachePath + " \\META-INF\\MANIFEST.MF " );
31 while ((lineStr = sr.ReadLine()) != null )
32 {
33 stringBuilder.Append(lineStr).Append( " \r\n " );
34 }
35 sr.Close();
36
37 // 删除解开的数据
38 Directory.Delete(cachePath, true );
39 if (File.Exists(jadFilePath))
40 {
41 // 备份数据
42 string pathBak = fileInfo.DirectoryName.ToLower().Replace( " uploads " , " uploadsBakJad " );
43 if ( ! Directory.Exists(pathBak))
44 Directory.CreateDirectory(pathBak);
45 File.Delete(jadFilePath.ToLower().Replace( " uploads " , " uploadsBakJad " ));
46 File.Move(jadFilePath, jadFilePath.ToLower().Replace( " uploads " , " uploadsBakJad " ));
47 }
48 StreamWriter wr = File.CreateText(jadFilePath);
49 wr.Write(stringBuilder);
50 wr.Close();
51 log.Info( " file " + jarfilePath + " is ok " );
52 }
53
54 private static void DecompressRar( string rarFileToDecompress, string directoryToSave)
55 {
56 string winrarExe = ConfigurationManager.AppSettings[ " winrarExepath " ];
57 if ( new FileInfo(winrarExe).Exists)
58 {
59 try
60 {
61 Process p = new Process();
62 // 需要启动的程序名
63 p.StartInfo.FileName = winrarExe;
64 // 参数
65 string arguments = @" x -inul -y -o+ " ;
66 arguments += " " + rarFileToDecompress + " " + directoryToSave;
67 p.StartInfo.Arguments = arguments;
68 p.Start(); // 启动
69 while ( ! p.HasExited)
70 { }
71 p.WaitForExit();
72 }
73 catch (Exception ee)
74 {
75 throw new Exception(ee.Message);
76 }
77 }
78 }