PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/workspace/Project.cs

https://github.com/moscrif/ide
C# | 1024 lines | 664 code | 207 blank | 153 comment | 116 complexity | 6a23e524bfe0736a6b551de11248634f MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using System.Xml;
  4. using System.Xml.Serialization;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using Moscrif.IDE.Devices;
  8. using MessageDialogs = Moscrif.IDE.Controls.MessageDialog;
  9. using Moscrif.IDE.Iface.Entities;
  10. using System.Security.Principal;
  11. using Moscrif.IDE.Controls;
  12. using System.Timers;
  13. using ICSharpCode.SharpZipLib.Zip;
  14. using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
  15. using Gtk;
  16. namespace Moscrif.IDE.Workspace
  17. {
  18. public class Project
  19. {
  20. public const string KEY_ICON = "icon";
  21. public const string KEY_ICON_BADA1 = "icon1";
  22. public const string KEY_SPLASH_BADA1 = "splash1";
  23. public const string KEY_ICON_BADA2 = "icon2";
  24. public const string KEY_SPLASH_BADA2 = "splash2";
  25. public const string KEY_ICON_BADA3 = "icon3";
  26. public const string KEY_SPLASH_BADA3 = "splash3";
  27. public const string KEY_MANIFEST = "manifest";
  28. public const string KEY_SPLASH = "splash";
  29. public const string KEY_APPLICATIONFILE = "applicationFile";
  30. public const string KEY_APPLICATIONID = "applicationId";
  31. public const string KEY_CERTIFICATE = "certificate";
  32. public const string KEY_KEY = "key";
  33. public const string KEY_PASSWORD = "password";
  34. public const string KEY_KEYSTORE = "keystore";
  35. public const string KEY_STOREPASSWORD = "storepassword";
  36. public const string KEY_ALIAS = "alias";
  37. public const string KEY_KEYPASSWORD = "keypassword";
  38. public const string KEY_INSTALLOCATION = "installLocation";
  39. public const string KEY_CODESIGNINGIDENTITY = "codeSigningIdentity";
  40. public const string KEY_SUPPORTEDDEVICES = "supportedDevices";
  41. /*public const string KEY_ICON3GS = "icon3gs";
  42. public const string KEY_ICON4 = "icon4+";
  43. public const string KEY_ICONPAD = "iconTablet";
  44. public const string KEY_SPLASH3GS = "splash3gs";
  45. public const string KEY_SPLASH4 = "splash4+";
  46. public const string KEY_SPLASHPAD = "splashTablet";*/
  47. public const string KEY_IP4ICON = "iPhone4-icon";
  48. public const string KEY_IP4SPLASH = "iPhone4-splash";
  49. public const string KEY_IP5ICON = "iPhone5-icon";
  50. public const string KEY_IP5SPLASH = "iPhone5-splash";
  51. public const string KEY_IPADICON = "iPad-icon";
  52. public const string KEY_IPADSPLASH = "iPad-splash";
  53. public const string KEY_INEWPADICON = "newiPad-icon";
  54. public const string KEY_INEWPADSPLASH = "newiPad-splash";
  55. public const string KEY_BUNDLEIDENTIFIER = "bundleIdentifier";
  56. public const string KEY_PERMISSION = "permission";
  57. public Project()
  58. {
  59. FilesProperty = new List<FileItem>();
  60. //BadaSettings = new Device();
  61. DevicesSettings = new List<Device>();
  62. ConditoinsDefine = new List<Condition>();
  63. //if (Resolution == null)
  64. // GenerateResolution();
  65. if (String.IsNullOrEmpty(ProjectOutput))
  66. ProjectOutput = MainClass.Workspace.OutputDirectory;
  67. }
  68. public Project(string filePath)
  69. {
  70. FilePath = filePath;
  71. FilesProperty = new List<FileItem>();
  72. //BadaSettings = new Device();
  73. DevicesSettings = new List<Device>();
  74. ConditoinsDefine = new List<Condition>();
  75. //if (Resolution == null)
  76. // GenerateResolution();
  77. if (String.IsNullOrEmpty(ProjectOutput))
  78. ProjectOutput = MainClass.Workspace.OutputDirectory;
  79. }
  80. public void GetAllFiles(ref List<string> filesList, string path, string extension){
  81. GetAllFiles(ref filesList, path, extension,false);
  82. }
  83. public void GetAllFiles(ref List<string> filesList, string path, string extension, bool skipMsc)
  84. {
  85. List<string> ext = new List<string>();
  86. if(!String.IsNullOrEmpty(extension))
  87. ext.Add(extension);
  88. GetAllFiles(ref filesList, path, ext,skipMsc);
  89. }
  90. public void GetAllFiles(ref List<string> filesList, string path, List<string> extension, bool skipMsc)
  91. {
  92. //this.AbsolutProjectDir
  93. if (!Directory.Exists(path)){
  94. Tool.Logger.LogDebugInfo(String.Format("Directory Not Exist-> {0}",path),null);
  95. return;
  96. }
  97. DirectoryInfo di = new DirectoryInfo(path);
  98. if((MainClass.Workspace == null) || (MainClass.Workspace.ActualProject == null)) return;
  99. //DirectoryInfo diOutput = new DirectoryInfo(MainClass.Workspace.ActualProject.OutputMaskToFullPath) ;
  100. DirectoryInfo diOutput = null;
  101. if(!String.IsNullOrEmpty(ProjectOutput))
  102. diOutput = new DirectoryInfo(this.OutputMaskToFullPath) ;
  103. foreach (DirectoryInfo d in di.GetDirectories()){
  104. int indx = -1;
  105. indx = MainClass.Settings.IgnoresFolders.FindIndex(x => x.Folder == d.Name && x.IsForPublish);
  106. if(!String.IsNullOrEmpty(ProjectOutput)){
  107. if(di.FullName == diOutput.FullName)
  108. continue;
  109. }
  110. if(indx<0){
  111. GetAllFiles(ref filesList, d.FullName,extension,skipMsc);
  112. }
  113. }
  114. foreach (FileInfo f in di.GetFiles()) {
  115. if (skipMsc && (f.Extension.ToUpper() == ".MSC")) continue;
  116. int indx = -1;
  117. indx = MainClass.Settings.IgnoresFiles.FindIndex(x => x.Folder == f.Name && x.IsForPublish);
  118. if(extension!=null || extension.Count>0){
  119. int inx = extension.FindIndex(x=>x.ToLower()==f.Extension.ToLower());
  120. if((inx>-1)&&(indx<0))
  121. filesList.Add( f.FullName );
  122. }else {
  123. if(indx<0)
  124. filesList.Add( f.FullName );
  125. }
  126. }
  127. }
  128. public FileItem ToggleExcludeFile(string filePath)
  129. {
  130. FileItem fi = FindFile(filePath);
  131. if (fi == null) {
  132. fi = new FileItem(filePath,true);
  133. FilesProperty.Add(fi);
  134. } else
  135. fi.IsExcluded = !fi.IsExcluded;
  136. return fi;
  137. /*FileItem fi = new FileItem();
  138. fi.IsExclude = true;
  139. fi.FilePath = filePath;
  140. FilesProperty.Add(fi);*/
  141. }
  142. [XmlArray("conditionDefines")]
  143. [XmlArrayItem("define")]
  144. public List<Condition> ConditoinsDefine;
  145. // nazovprojektu.msp.nazovPc-Username.user
  146. private ProjectUserFile projectUserSetting;
  147. [XmlIgnore]
  148. public ProjectUserFile ProjectUserSetting{
  149. get{
  150. if(projectUserSetting == null){
  151. string mspFile= System.IO.Path.GetFileName(FilePath);
  152. string mspPath = System.IO.Path.GetDirectoryName(FilePath);
  153. string userName = String.Format("{0}.{1}-{2}.user",mspFile,Environment.MachineName,Environment.UserName);
  154. string userPath = System.IO.Path.Combine(mspPath,userName);
  155. if(System.IO.File.Exists(userPath)){
  156. projectUserSetting = ProjectUserFile.OpenProjectUserFile(userPath);
  157. } else {
  158. projectUserSetting =new ProjectUserFile(userPath);
  159. }
  160. }
  161. return projectUserSetting;
  162. }
  163. }
  164. /*
  165. [XmlArray("combinePublishes")]
  166. [XmlArrayItem("publish")]
  167. public List<CombinePublish> CombinePublish;
  168. [XmlAttribute("publishPageIndex")]
  169. public int PublishPage ;
  170. */
  171. [XmlAttribute("includeAllResolution")]
  172. public bool IncludeAllResolution = false;
  173. [XmlAttribute("applicationType")]
  174. public string ApplicationType = "application";
  175. private AppFile appFile;
  176. [XmlIgnore]
  177. public AppFile AppFile
  178. {
  179. get {
  180. //if (appFile != null)
  181. // return appFile;
  182. appFile = new AppFile( MainClass.Workspace.GetFullPath(AppFilePath));
  183. return appFile;
  184. }
  185. set {
  186. appFile = value;
  187. }
  188. }
  189. private string absolutProjectDir = String.Empty;
  190. [XmlIgnore]
  191. public string AbsolutProjectDir
  192. {
  193. get {
  194. //if(String.IsNullOrEmpty(absolutProjectDir)){
  195. string prjDir = System.IO.Path.GetFileNameWithoutExtension(AbsolutAppFilePath);
  196. absolutProjectDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(AbsolutAppFilePath),prjDir);
  197. //}
  198. return absolutProjectDir;
  199. //return System.IO.Path.Combine(MainClass.Workspace.RootDirectory,ProjectDir);
  200. //return MainClass.Workspace.GetFullPath(ProjectDir);
  201. }
  202. }
  203. [XmlIgnore]
  204. public string FilePath
  205. {
  206. get;
  207. set;
  208. }
  209. //[XmlAttribute("projectName")]
  210. [XmlIgnore]
  211. public string ProjectName{
  212. get{
  213. return AppFile.Name;
  214. }
  215. }
  216. //[XmlAttribute("projectDir")]
  217. /* [XmlIgnore]
  218. public string ProjectDir{
  219. get{
  220. //return AppFile.Name;
  221. }
  222. }*/
  223. public bool NewSkin =false;
  224. [XmlAttribute("projectOutput")]
  225. public string ProjectOutput;
  226. [XmlAttribute("facebookAppID")]
  227. public string FacebookAppID;
  228. [XmlElement("publishTyp")]
  229. public int TypPublish = 0;
  230. [XmlIgnore]
  231. public string OutputMaskToFullPath{
  232. get{
  233. return ConvertProjectMaskPathToFull(ProjectOutput);
  234. }
  235. }
  236. public string ConvertProjectMaskPathToFull(string mask){
  237. if(MainClass.Workspace!=null && !String.IsNullOrEmpty(MainClass.Workspace.FilePath)){
  238. string path = MainClass.Workspace.ConvertOutputMaskToFullPath(mask);
  239. path = path.Replace("$(publish_dir)", MainClass.Settings.PublishDirectory);
  240. if(path.Contains("$(project_dir)"))
  241. path = path.Replace("$(project_dir)", this.AbsolutProjectDir);
  242. return path;
  243. }
  244. return MainClass.Paths.WorkDir;
  245. }
  246. [XmlAttribute("projectArtefact")]
  247. public string ProjectArtefac;
  248. [XmlAttribute("appFile")]
  249. public string AppFilePath;
  250. [XmlIgnore]
  251. public string RelativeAppFilePath
  252. {
  253. get {
  254. return Tool.FileUtility.GetSystemPath(AppFilePath);
  255. /*string absPath = AppFilePath.Replace('/',Path.DirectorySeparatorChar);
  256. absPath = absPath.Replace('\\',Path.DirectorySeparatorChar);
  257. return absPath;*/
  258. }
  259. }
  260. private string absolutAppFilePath =string.Empty;
  261. [XmlIgnore]
  262. public string AbsolutAppFilePath
  263. {
  264. get {
  265. //if(String.IsNullOrEmpty(absolutAppFilePath)){
  266. absolutAppFilePath =MainClass.Workspace.GetFullPath(this.AppFilePath);
  267. //}
  268. return absolutAppFilePath;
  269. }
  270. }
  271. /*[XmlAttribute("startupFile")]
  272. public string StartFile;*/
  273. [XmlIgnore]
  274. public string StartFile{
  275. get{
  276. if(!string.IsNullOrEmpty(AppFile.Main)){
  277. string file = System.IO.Path.Combine(this.absolutProjectDir,AppFile.Main);
  278. return MainClass.Workspace.GetRelativePath(file);
  279. } else return "";
  280. }
  281. set{
  282. string file = System.IO.Path.GetFileName(value);
  283. AppFile.Main = file;
  284. }
  285. }
  286. [XmlArray("fileProperties")]
  287. [XmlArrayItem("property")]
  288. public List<FileItem> FilesProperty;
  289. [XmlArray("devices")]
  290. [XmlArrayItem("device")]
  291. public List<Device> DevicesSettings;
  292. public void GenerateDevices(){
  293. GenerateDevices("","");
  294. }
  295. public List<PublishProperty> GeneratePublishPropertisMask(int deviceTyp){
  296. List<PublishProperty> list = new List<PublishProperty>();
  297. if(deviceTyp == (int)DeviceType.Android_1_6){
  298. list = new List<PublishProperty>();
  299. list.Add(new PublishProperty(KEY_ICON));
  300. list.Add(new PublishProperty(KEY_SPLASH));
  301. list.Add(new PublishProperty(KEY_BUNDLEIDENTIFIER));
  302. list.Add(new PublishProperty(KEY_ALIAS));
  303. list.Add(new PublishProperty(KEY_KEYSTORE));
  304. list.Add(new PublishProperty(KEY_KEYPASSWORD));
  305. list.Add(new PublishProperty(KEY_STOREPASSWORD));
  306. list.Add(new PublishProperty(KEY_SUPPORTEDDEVICES));
  307. list.Add(new PublishProperty(KEY_PERMISSION));
  308. }
  309. if(deviceTyp == (int)DeviceType.Android_2_2){
  310. list = new List<PublishProperty>();
  311. list.Add(new PublishProperty(KEY_ICON));
  312. list.Add(new PublishProperty(KEY_SPLASH));
  313. list.Add(new PublishProperty(KEY_BUNDLEIDENTIFIER));
  314. list.Add(new PublishProperty(KEY_ALIAS));
  315. list.Add(new PublishProperty(KEY_KEYSTORE));
  316. list.Add(new PublishProperty(KEY_KEYPASSWORD));
  317. list.Add(new PublishProperty(KEY_STOREPASSWORD));
  318. list.Add(new PublishProperty(KEY_SUPPORTEDDEVICES));
  319. list.Add(new PublishProperty(KEY_INSTALLOCATION));
  320. list.Add(new PublishProperty(KEY_PERMISSION));
  321. }
  322. if((deviceTyp == (int)DeviceType.Bada_1_0) || (deviceTyp == (int)DeviceType.Bada_1_1) || (deviceTyp == (int)DeviceType.Bada_1_2)
  323. || (deviceTyp == (int)DeviceType.Bada_2_0) ){
  324. list = new List<PublishProperty>();
  325. list.Add(new PublishProperty(KEY_ICON));
  326. list.Add(new PublishProperty(KEY_SPLASH));
  327. /*dpd.Device.PublishPropertisMask.Add(new PublishProperty(KEY_ICON_BADA1));
  328. dpd.Device.PublishPropertisMask.Add(new PublishProperty(KEY_SPLASH_BADA1));
  329. dpd.Device.PublishPropertisMask.Add(new PublishProperty(KEY_ICON_BADA2));
  330. dpd.Device.PublishPropertisMask.Add(new PublishProperty(KEY_SPLASH_BADA2));*/
  331. /*
  332. TOTO len pre badu 1.2 - ked bude
  333. dpd.Device.PublishPropertisMask.Add(new PublishProperty(KEY_ICON_BADA1));
  334. dpd.Device.PublishPropertisMask.Add(new PublishProperty(KEY_SPLASH_BADA1));*/
  335. list.Add(new PublishProperty(KEY_MANIFEST));
  336. }
  337. if(deviceTyp == (int)DeviceType.Symbian_9_4){
  338. list = new List<PublishProperty>();
  339. list.Add(new PublishProperty(KEY_ICON));
  340. list.Add(new PublishProperty(KEY_SPLASH));
  341. list.Add(new PublishProperty(KEY_APPLICATIONID));
  342. list.Add(new PublishProperty(KEY_CERTIFICATE));
  343. list.Add(new PublishProperty(KEY_KEY));
  344. list.Add(new PublishProperty(KEY_PASSWORD));
  345. }
  346. if(deviceTyp == (int)DeviceType.iOS_5_0){
  347. list = new List<PublishProperty>();
  348. list.Add(new PublishProperty(KEY_ICON));
  349. list.Add(new PublishProperty(KEY_SPLASH));
  350. list.Add(new PublishProperty(KEY_CODESIGNINGIDENTITY));
  351. list.Add(new PublishProperty(KEY_SUPPORTEDDEVICES));
  352. list.Add(new PublishProperty(KEY_IP4ICON));
  353. list.Add(new PublishProperty(KEY_IP4SPLASH ));
  354. list.Add(new PublishProperty(KEY_IP5ICON ));
  355. list.Add(new PublishProperty(KEY_IP5SPLASH ));
  356. list.Add(new PublishProperty(KEY_IPADICON ));
  357. list.Add(new PublishProperty(KEY_IPADSPLASH ));
  358. list.Add(new PublishProperty(KEY_INEWPADICON ));
  359. list.Add(new PublishProperty(KEY_INEWPADSPLASH ));
  360. /*list.Add(new PublishProperty(KEY_ICON3GS));
  361. list.Add(new PublishProperty(KEY_ICON4));
  362. list.Add(new PublishProperty(KEY_ICONPAD));
  363. list.Add(new PublishProperty(KEY_SPLASH3GS));
  364. list.Add(new PublishProperty(KEY_SPLASH4));
  365. list.Add(new PublishProperty(KEY_SPLASHPAD));*/
  366. }
  367. if(deviceTyp == (int)DeviceType.WindowsMobile_5 || (deviceTyp == (int)DeviceType.WindowsMobile_6) || (deviceTyp == (int)DeviceType.PocketPC_2003SE)){
  368. list = new List<PublishProperty>();
  369. list.Add(new PublishProperty(KEY_ICON));
  370. list.Add(new PublishProperty(KEY_SPLASH));
  371. }
  372. if(deviceTyp == (int)DeviceType.Windows){
  373. list = new List<PublishProperty>();
  374. list.Add(new PublishProperty(KEY_ICON));
  375. list.Add(new PublishProperty(KEY_SPLASH));
  376. }
  377. if(deviceTyp == (int)DeviceType.MacOs){
  378. list = new List<PublishProperty>();
  379. list.Add(new PublishProperty(KEY_ICON));
  380. list.Add(new PublishProperty(KEY_SPLASH));
  381. }
  382. return list;
  383. }
  384. public void GenerateDevices(string skin, string theme, string[] fonts){
  385. if(this.DevicesSettings == null)
  386. this.DevicesSettings = new List<Device>();
  387. foreach (Rule rl in MainClass.Settings.Platform.Rules){
  388. Device dvc = this.DevicesSettings.Find(x => x.TargetPlatformId == rl.Id);
  389. if (dvc == null) {
  390. dvc = new Device();
  391. dvc.TargetPlatformId = rl.Id;
  392. dvc.Includes.Skin.Name = skin;
  393. dvc.Includes.Skin.Theme = theme;
  394. if(fonts == null)
  395. dvc.Includes.Fonts = new string[]{};
  396. else
  397. dvc.Includes.Fonts = fonts;
  398. this.DevicesSettings.Add(dvc);
  399. }
  400. if ((dvc.PublishPropertisMask == null) || dvc.PublishPropertisMask.Count<1){
  401. dvc.PublishPropertisMask = GeneratePublishPropertisMask(rl.Id );
  402. }
  403. }
  404. }
  405. public void GenerateDevices(string skin, string theme){
  406. GenerateDevices(skin,theme,null);
  407. }
  408. internal void Save()
  409. {
  410. XmlWriterSettings xmlSettings = new XmlWriterSettings();
  411. xmlSettings.NewLineChars = "\n";//Environment.NewLine;
  412. xmlSettings.Indent = true;
  413. xmlSettings.CloseOutput = true;
  414. XmlSerializer x_serial = new XmlSerializer( typeof( Project ) );
  415. using (XmlWriter wr = XmlWriter.Create( this.FilePath, xmlSettings )) {
  416. x_serial.Serialize( wr, this );
  417. }
  418. XmlSerializer x_serial_PU = new XmlSerializer( typeof( ProjectUserFile ) );
  419. using (XmlWriter wr = XmlWriter.Create( this.ProjectUserSetting.FilePath, xmlSettings )) {
  420. x_serial_PU.Serialize( wr, this.ProjectUserSetting );
  421. }
  422. }
  423. private ProgressDialog progressDialog;
  424. public bool Export(string outputFile, bool Archive){
  425. /*if (System.IO.File.Exists(outputFile)){
  426. MessageDialogs md =
  427. new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, MainClass.Languages.Translate("file_notcreate_is_exist") ,outputFile, Gtk.MessageType.Error);
  428. return false;
  429. }*/
  430. string[] filePaths = Directory.GetFiles(AbsolutProjectDir, "*",SearchOption.AllDirectories);
  431. List<string> fonts = new List<string>();
  432. int lng = filePaths.Length;
  433. int folderOffset = MainClass.Workspace.RootDirectory.Length;//compressDir.Length + (compressDir.EndsWith("\\") ? 0 : 1);
  434. string signingOld = String.Empty;
  435. Device device = this.DevicesSettings.Find(x=>x.Devicetype == DeviceType.iOS_5_0);
  436. if(device!= null){
  437. PublishProperty ppSigning = device.PublishPropertisMask.Find(x=>x.PublishName== KEY_CODESIGNINGIDENTITY);
  438. if(ppSigning!= null){
  439. signingOld = ppSigning.PublishValue;
  440. ppSigning.PublishValue = "";
  441. try{
  442. Save();
  443. } catch (Exception ex){
  444. Tool.Logger.Error(ex.Message);
  445. }
  446. }
  447. }
  448. if(Archive){
  449. foreach (string lib in this.AppFile.Libs){
  450. string libPath = System.IO.Path.Combine(MainClass.Workspace.RootDirectory,lib);
  451. if(Directory.Exists(libPath)){
  452. try{
  453. filePaths = Directory.GetFiles(libPath, "*",SearchOption.AllDirectories);
  454. lng = lng + filePaths.Length;
  455. }catch(Exception ex) {
  456. Tool.Logger.Error(ex.Message);
  457. }
  458. }
  459. }
  460. filePaths = Directory.GetFiles(MainClass.Workspace.RootDirectory, "*.ttf",SearchOption.TopDirectoryOnly);
  461. if(MainClass.Platform.IsMac){// for Mac UpperCase
  462. string[] filePaths2 = Directory.GetFiles(MainClass.Workspace.RootDirectory, "*.TTF",SearchOption.TopDirectoryOnly);
  463. var list = new List<string>();
  464. list.AddRange(filePaths);
  465. list.AddRange(filePaths2);
  466. filePaths = list.ToArray();
  467. }
  468. foreach (Device d in this.DevicesSettings){
  469. foreach (string font in d.Includes.Fonts){
  470. string fontPath = System.IO.Path.Combine(MainClass.Workspace.RootDirectory ,font);
  471. if( System.IO.File.Exists(fontPath) && fonts.FindIndex(x=>x == fontPath)<0 ){
  472. System.IO.FileInfo fi = new FileInfo(fontPath);
  473. if(fi.DirectoryName == MainClass.Workspace.RootDirectory) // only font from workspace
  474. fonts.Add(fontPath);
  475. }
  476. }
  477. }
  478. lng = lng +fonts.Count;
  479. }
  480. progressDialog = new ProgressDialog("Compressed...",ProgressDialog.CancelButtonType.None,lng+2,MainClass.MainWindow);
  481. /*Timer timer = new Timer();
  482. timer.Interval = 240;
  483. timer.Elapsed += new ElapsedEventHandler(OnTimeElapsed);
  484. timer.Start();*/
  485. FileStream fsOut = File.Create(outputFile);
  486. ZipOutputStream zipStream = new ZipOutputStream(fsOut);
  487. zipStream.SetLevel(4);
  488. string[] files = new string[] {this.AbsolutAppFilePath,this.FilePath};
  489. foreach (string file in files){
  490. FileInfo fi = new FileInfo(file);
  491. string entryName = System.IO.Path.GetFileName(file); //file.Substring(folderOffset);
  492. entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
  493. ZipEntry newEntry = new ZipEntry(entryName);
  494. newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity
  495. // Specifying the AESKeySize triggers AES encryption. Allowable values are 0 (off), 128 or 256.
  496. // newEntry.AESKeySize = 256;
  497. // To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
  498. // you need to do one of the following: Specify UseZip64.Off, or set the Size.
  499. // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
  500. // but the zip will be in Zip64 format which not all utilities can understand.
  501. // zipStream.UseZip64 = UseZip64.Off;
  502. newEntry.Size = fi.Length;
  503. zipStream.PutNextEntry(newEntry);
  504. // Zip the file in buffered chunks
  505. // the "using" will close the stream even if an exception occurs
  506. progressDialog.Update(entryName);
  507. byte[ ] buffer = new byte[4096];
  508. using (FileStream streamReader = File.OpenRead(file)) {
  509. ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(streamReader, zipStream, buffer);
  510. }
  511. zipStream.CloseEntry();
  512. }
  513. foreach (string file in fonts){
  514. FileInfo fi = new FileInfo(file);
  515. string entryName = System.IO.Path.GetFileName(file); //file.Substring(folderOffset);
  516. entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
  517. ZipEntry newEntry = new ZipEntry(entryName);
  518. newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity
  519. // Specifying the AESKeySize triggers AES encryption. Allowable values are 0 (off), 128 or 256.
  520. // newEntry.AESKeySize = 256;
  521. // To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
  522. // you need to do one of the following: Specify UseZip64.Off, or set the Size.
  523. // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
  524. // but the zip will be in Zip64 format which not all utilities can understand.
  525. // zipStream.UseZip64 = UseZip64.Off;
  526. newEntry.Size = fi.Length;
  527. zipStream.PutNextEntry(newEntry);
  528. // Zip the file in buffered chunks
  529. // the "using" will close the stream even if an exception occurs
  530. progressDialog.Update(entryName);
  531. byte[ ] buffer = new byte[4096];
  532. using (FileStream streamReader = File.OpenRead(file)) {
  533. ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(streamReader, zipStream, buffer);
  534. }
  535. zipStream.CloseEntry();
  536. }
  537. CompressFolder(this.AbsolutProjectDir, zipStream, folderOffset);
  538. if(Archive){
  539. foreach (string lib in this.AppFile.Libs){
  540. string libPath = System.IO.Path.Combine(MainClass.Workspace.RootDirectory,lib);
  541. if(System.IO.Directory.Exists(libPath)){
  542. CompressFolder(libPath, zipStream, folderOffset);
  543. }
  544. }
  545. }
  546. if(!String.IsNullOrEmpty(signingOld)){
  547. device = this.DevicesSettings.Find(x=>x.Devicetype == DeviceType.iOS_5_0);
  548. if(device!= null){
  549. PublishProperty ppSigning = device.PublishPropertisMask.Find(x=>x.PublishName== KEY_CODESIGNINGIDENTITY);
  550. if(ppSigning!= null){
  551. ppSigning.PublishValue = signingOld;
  552. try{
  553. Save();
  554. } catch (Exception ex){
  555. Tool.Logger.Error(ex.Message);
  556. }
  557. }
  558. }
  559. }
  560. zipStream.IsStreamOwner = true;
  561. zipStream.Close();
  562. progressDialog.Destroy();
  563. return true;
  564. }
  565. private void CompressFolder(string path, ZipOutputStream zipStream, int folderOffset) {
  566. string[] files = Directory.GetFiles(path);
  567. foreach (string filename in files) {
  568. FileInfo fi = new FileInfo(filename);
  569. int indx = -1;
  570. indx = MainClass.Settings.IgnoresFiles.FindIndex(x => x.Folder == fi.Name && x.IsForIde);
  571. if(indx >-1) continue;
  572. string entryName = filename.Substring(folderOffset); // Makes the name in zip based on the folder
  573. entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
  574. ZipEntry newEntry = new ZipEntry(entryName);
  575. newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity
  576. // Specifying the AESKeySize triggers AES encryption. Allowable values are 0 (off), 128 or 256.
  577. // newEntry.AESKeySize = 256;
  578. // To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
  579. // you need to do one of the following: Specify UseZip64.Off, or set the Size.
  580. // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
  581. // but the zip will be in Zip64 format which not all utilities can understand.
  582. // zipStream.UseZip64 = UseZip64.Off;
  583. newEntry.Size = fi.Length;
  584. zipStream.PutNextEntry(newEntry);
  585. // Zip the file in buffered chunks
  586. // the "using" will close the stream even if an exception occurs
  587. progressDialog.Update(entryName);
  588. byte[ ] buffer = new byte[4096];
  589. using (FileStream streamReader = File.OpenRead(filename)) {
  590. ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(streamReader, zipStream, buffer);
  591. }
  592. zipStream.CloseEntry();
  593. }
  594. string[ ] folders = Directory.GetDirectories(path);
  595. foreach (string folder in folders) {
  596. string folderName = System.IO.Path.GetFileName(folder);
  597. int indx = MainClass.Settings.IgnoresFolders.FindIndex(x => x.Folder == folderName && x.IsForIde);
  598. if(indx <0 )
  599. CompressFolder(folder, zipStream, folderOffset);
  600. }
  601. }
  602. private void OnTimeElapsed(object o, ElapsedEventArgs args){
  603. /*Gtk.Application.Invoke(delegate {
  604. if(progressDialog != null)
  605. progressDialog.AutomaticUpdate();
  606. });*/
  607. if(progressDialog != null)
  608. progressDialog.AutomaticUpdate();
  609. while (Application.EventsPending ())
  610. Application.RunIteration ();
  611. }
  612. private FileItem FindFile(string filePath)
  613. {
  614. return FilesProperty.Find(x => x.SystemFilePath
  615. == filePath);
  616. }
  617. /*private void GenerateResolution()
  618. {
  619. Resolution = new Condition();
  620. Resolution.Name = MainClass.Settings.Resolution.Name;
  621. Resolution.Id = MainClass.Settings.Resolution.Id;
  622. Resolution.Rules = new List<Rule>(MainClass.Settings.Resolution.Rules.ToArray());
  623. }*/
  624. public List<string> ConvertArtefacToNames(string platform)
  625. {
  626. if (String.IsNullOrEmpty(this.ProjectArtefac)) {
  627. string name = System.IO.Path.GetFileNameWithoutExtension(this.AppFilePath);
  628. this.ProjectArtefac = String.Format("{0}_$({1})_$({2})", name, MainClass.Settings.Platform.Name, MainClass.Settings.Resolution.Name);
  629. }
  630. return new List<string>();
  631. }
  632. static internal Project OpenProject(string filePath,bool showError)
  633. {
  634. return OpenProject(filePath,true,false);
  635. }
  636. static internal Project OpenProject(string filePath)
  637. {
  638. return OpenProject(filePath,true);
  639. }
  640. static internal Project OpenProject(string filePath,bool showError,bool throwError)
  641. {
  642. if (System.IO.File.Exists(filePath)){
  643. try{
  644. using (FileStream fs = File.OpenRead(filePath)) {
  645. XmlSerializer serializer = new XmlSerializer(typeof(Project));
  646. Project p = (Project)serializer.Deserialize(fs);
  647. p.FilePath = filePath;
  648. if(!System.IO.File.Exists(p.AbsolutAppFilePath)){
  649. if(showError){
  650. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_is_corrupted_f2", filePath), "", Gtk.MessageType.Error,null);
  651. md.ShowDialog();
  652. } else if(throwError){
  653. throw new Exception(MainClass.Languages.Translate("project_is_corrupted_f2", filePath));
  654. }
  655. return null;
  656. }
  657. return p;
  658. }
  659. }catch(Exception ex){
  660. Tool.Logger.Error(ex.Message);
  661. if(throwError){
  662. throw ex;
  663. }
  664. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.OkCancel, MainClass.Languages.Translate("project_is_corrupted", filePath), MainClass.Languages.Translate("delete_corupted_project"), Gtk.MessageType.Question,null);
  665. int res = md.ShowDialog();
  666. if(res == (int)Gtk.ResponseType.Ok) {
  667. try{
  668. System.IO.File.Delete(filePath);
  669. }catch(Exception exx){
  670. MessageDialogs mdError = new MessageDialogs(MessageDialogs.DialogButtonType.OkCancel, "Error", exx.Message, Gtk.MessageType.Error,null);
  671. mdError.ShowDialog();
  672. }
  673. }
  674. return null;
  675. }
  676. }else {
  677. if(showError){
  678. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_not_exit_f1", filePath), "", Gtk.MessageType.Error,null);
  679. md.ShowDialog();
  680. } if(throwError){
  681. throw new Exception(MainClass.Languages.Translate("project_is_corrupted_f2", filePath));
  682. }
  683. return null;
  684. }
  685. }
  686. /*public void GetAllFiles(ref List<string> filesList,string path)
  687. {
  688. if (!Directory.Exists(path))
  689. return;
  690. DirectoryInfo di = new DirectoryInfo(path);
  691. foreach (DirectoryInfo d in di.GetDirectories()){
  692. int indx = -1;
  693. indx = MainClass.Settings.IgnoresFolders.FindIndex(x => x.Folder == d.Name && x.IsForIde);
  694. if(indx<0){
  695. GetAllFiles(ref filesList, d.FullName);
  696. }
  697. }
  698. foreach (FileInfo f in di.GetFiles()) {
  699. //if (f.Extension == ".ms") continue;
  700. filesList.Add( f.FullName );
  701. }
  702. }*/
  703. public void GeneratePublishCombination()
  704. {
  705. if(this.ProjectUserSetting.CombinePublish != null)
  706. this.ProjectUserSetting.CombinePublish.Clear();
  707. if (String.IsNullOrEmpty(this.ProjectArtefac)){
  708. string name = System.IO.Path.GetFileNameWithoutExtension(this.AppFilePath);
  709. this.ProjectArtefac = String.Format("{0}_$({1})_$({2})", name, MainClass.Settings.Platform.Name, MainClass.Settings.Resolution.Name);
  710. }
  711. List<Condition> fullCondition = new List<Condition>();
  712. //fullCondition.Add(MainClass.Settings.Platform.Clone());
  713. /*if ((this.SelectResolution == null) ||
  714. (this.SelectResolution.Count < 1)) {
  715. this.SelectResolution = new List<int>();
  716. SelectResolution.Add(-1);
  717. }*/
  718. // pridam rozlisenie,
  719. //fullCondition.Add(this.Resolution.Clone());
  720. fullCondition.Add(MainClass.Settings.Resolution.Clone());
  721. // pridam Conditions, ale len tie ktore su vmene pre aplikaciu
  722. foreach (Condition con in this.ConditoinsDefine) {
  723. int i = this.ProjectArtefac.IndexOf(String.Format("$({0})", con.Name));
  724. if (i > -1)
  725. fullCondition.Add(con.Clone());
  726. }
  727. int indx = 0;
  728. List<CombinePublish> listCC = new List<CombinePublish>();
  729. // kombinacie si predplnim aplikaciami
  730. foreach (Rule rl in MainClass.Settings.Platform.Rules) {
  731. CombinePublish cc = new CombinePublish();
  732. CombineCondition cr = new CombineCondition();
  733. cr.RuleId = rl.Id;
  734. cr.RuleName = rl.Specific;
  735. cr.ConditionId = MainClass.Settings.Platform.Id;
  736. cr.ConditionName = MainClass.Settings.Platform.Name;
  737. cc.combineRule = new List<CombineCondition>();
  738. cc.combineRule.Add(cr);
  739. //cc.ProjectName = this.ProjectArtefac;
  740. cc.ProjectName = this.ProjectArtefac.Replace(String.Format("$({0})", cr.ConditionName), cr.RuleName);
  741. listCC.Add(cc);
  742. }
  743. // samotne kombibnacie
  744. while (indx < fullCondition.Count) {
  745. List<CombinePublish> listCCcopy = MainClass.Tools.Clone<CombinePublish>(listCC);
  746. listCC.Clear();
  747. foreach (CombinePublish cc in listCCcopy)
  748. foreach (Rule rl in fullCondition [indx].Rules){
  749. CombinePublish cc2 = cc.Clone();
  750. CombineCondition cr = new CombineCondition();
  751. cr.RuleId = rl.Id;
  752. if (fullCondition [indx].Name == MainClass.Settings.Resolution.Name)
  753. cr.RuleName = rl.Specific;
  754. else
  755. cr.RuleName = rl.Name;
  756. cr.ConditionId = fullCondition [indx].Id;
  757. cr.ConditionName = fullCondition [indx].Name;
  758. cc2.combineRule.Add(cr);
  759. cc2.ProjectName = cc2.ProjectName.Replace(String.Format("$({0})", cr.ConditionName), cr.RuleName);
  760. listCC.Add(cc2);
  761. }
  762. indx++;
  763. }
  764. ProjectUserSetting.CombinePublish = new List<CombinePublish>(listCC.ToArray());
  765. // return listCC;
  766. }
  767. }
  768. public class FileItem
  769. {
  770. public FileItem()
  771. {
  772. }
  773. public FileItem(string Path,bool Exluded)
  774. {
  775. this.FilePath = Path;
  776. this.IsExcluded = Exluded;
  777. }
  778. [XmlAttribute("path")]
  779. public string FilePath;
  780. [XmlIgnore]
  781. public string SystemFilePath{
  782. get{
  783. return Tool.FileUtility.GetSystemPath(FilePath);
  784. }
  785. }
  786. [XmlAttribute("isDirectory")]
  787. public bool IsDirectory;
  788. [XmlAttribute("excluded")]
  789. public Boolean IsExcluded;
  790. [XmlArray("conditions")]
  791. [XmlArrayItem("condition")]
  792. public List<ConditionRule> ConditionValues;
  793. }
  794. public enum TypeFile
  795. {
  796. AppFile,
  797. Directory,
  798. SourceFile,
  799. StartFile,
  800. ExcludetFile
  801. }
  802. }