PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/workspace/Workspace.cs

https://github.com/moscrif/ide
C# | 932 lines | 631 code | 164 blank | 137 comment | 93 complexity | a8f3ea8588ab151db0e95b327c785143 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.Editors;
  8. using MessageDialogs = Moscrif.IDE.Controls.MessageDialog;
  9. using Moscrif.IDE.Tool;
  10. using Moscrif.IDE.Controls;
  11. using Moscrif.IDE.Iface.Entities;
  12. using System.Threading;
  13. using System.Diagnostics;
  14. using Moscrif.IDE.Iface;
  15. namespace Moscrif.IDE.Workspace
  16. {
  17. public class Workspace
  18. {
  19. #region Public Property
  20. private string filePath;
  21. [XmlIgnore]
  22. public string FilePath
  23. {
  24. get { return filePath; }
  25. set {
  26. filePath = value;
  27. if (!String.IsNullOrEmpty(filePath))
  28. RootDirectory = System.IO.Path.GetDirectoryName(filePath);
  29. }
  30. }
  31. [XmlIgnore]
  32. public List<Project> Projects;
  33. [XmlIgnore]
  34. public string RootDirectory;
  35. [XmlIgnore]
  36. public Project ActualProject
  37. {
  38. get;
  39. set;
  40. }
  41. [XmlArray("projects")]
  42. [XmlArrayItem("project")]
  43. public List<string> ProjectsFile;
  44. [XmlArray("opened")]
  45. [XmlArrayItem("file")]
  46. public List<string> OpenFiles;
  47. //public List<string> PublishDevices;
  48. [XmlAttribute("fileExplorerPath")]
  49. public string FileExplorerPath;
  50. [XmlAttribute("vertBodyHeight")]
  51. public int VpBodyHeight;
  52. [XmlAttribute("horzMiddleBodyHeight")]
  53. public int HpBodyMiddleWidth;
  54. [XmlAttribute("horzRightBodyWidth")]
  55. public int HpBodyRightWidth;
  56. [XmlAttribute("vertOutputWidth")]
  57. public int HpOutputWidth;
  58. [XmlAttribute("name")]
  59. public string Name;
  60. [XmlAttribute("outputDir")]
  61. public string OutputDirectory;
  62. [XmlAttribute("tag")]
  63. public int Tag;
  64. [XmlAttribute("signapp")]
  65. public bool SignApp;
  66. [XmlAttribute("showLeftPane")]
  67. public bool ShowLeftPane = true;
  68. [XmlAttribute("showRightPane")]
  69. public bool ShowRightPane = true;
  70. [XmlAttribute("showBottomPane")]
  71. public bool ShowBottomPane = true;
  72. [XmlAttribute("selectedProject")]
  73. public String ActualProjectPath
  74. {
  75. get;
  76. set;
  77. }
  78. [XmlAttribute("showalllibs")]
  79. public bool ShowAllLibs
  80. {
  81. get;
  82. set;
  83. }
  84. [XmlAttribute("selectedResolution")]
  85. public string ActualResolution
  86. {
  87. get;
  88. set;
  89. }
  90. [XmlAttribute("selectedDevices")]
  91. public int ActualDevice
  92. {
  93. get;
  94. set;
  95. }
  96. public void SetActualProject(string projectFile)
  97. {
  98. ActualProject = FindProject(projectFile);
  99. if(ActualProject!=null)
  100. ActualProjectPath = ActualProject.FilePath;
  101. }
  102. [XmlIgnore]
  103. public string OutputMaskToFullPath{
  104. get{
  105. return ConvertOutputMaskToFullPath(OutputDirectory);
  106. }
  107. }
  108. // nazovprojektu.msp.nazovPc-Username.user
  109. private WorkspaceUserFile workspaceUserSetting;
  110. [XmlIgnore]
  111. public WorkspaceUserFile WorkspaceUserSetting{
  112. get{
  113. if(workspaceUserSetting == null){
  114. if (string.IsNullOrEmpty(FilePath)){
  115. workspaceUserSetting =new WorkspaceUserFile();
  116. return workspaceUserSetting;
  117. }
  118. string mspPath = System.IO.Path.GetDirectoryName(FilePath);
  119. string userName = String.Format("{0}.{1}-{2}.user",Name,Environment.MachineName,Environment.UserName);
  120. string userPath = System.IO.Path.Combine(mspPath,userName);
  121. if(System.IO.File.Exists(userPath)){
  122. workspaceUserSetting = WorkspaceUserFile.OpenWorkspaceUserFile(userPath);
  123. } else {
  124. workspaceUserSetting =new WorkspaceUserFile(userPath);
  125. }
  126. }
  127. return workspaceUserSetting;
  128. }
  129. }
  130. public string ConvertOutputMaskToFullPath(string mask){
  131. if(String.IsNullOrEmpty(mask)) return "";
  132. mask = mask.Replace('/',Path.DirectorySeparatorChar);
  133. mask = mask.Replace('\\',Path.DirectorySeparatorChar);
  134. string path = mask.Replace("$(workspace_dir)", RootDirectory);
  135. path = path.Replace("$(workspace_work)", MainClass.Paths.WorkDir);
  136. return path;
  137. }
  138. #endregion
  139. //private Tools tools = new Tools();
  140. public Workspace()
  141. {
  142. FilePath = String.Empty;
  143. //System.IO.Path.Combine(tools.ConfingDir, "workspace.wsp");
  144. Projects = new List<Project>();
  145. ProjectsFile = new List<string>();
  146. OpenFiles = new List<string>();
  147. }
  148. /* public Workspace(string filePath)
  149. {
  150. FilePath = filePath;
  151. Projects = new List<Project>();
  152. ProjectsFile = new List<string>();
  153. OpenFiles = new List<string>();
  154. }*/
  155. public void SaveWorkspace(List<string> openFile, int vpBodyHeight, int hpBodyMiddleWidth,int hpBodyRightWidth, int hpOutputWidth)
  156. {
  157. foreach (Project project in Projects)
  158. SaveProject(project);
  159. HpOutputWidth = hpOutputWidth;
  160. VpBodyHeight = vpBodyHeight;
  161. HpBodyMiddleWidth = hpBodyMiddleWidth;
  162. HpBodyRightWidth = hpBodyRightWidth;
  163. OpenFiles = openFile;
  164. SaveWorkspace();
  165. }
  166. public void SaveWorkspace()
  167. {
  168. if (String.IsNullOrEmpty(FilePath))
  169. return;
  170. XmlWriterSettings xmlSettings = new XmlWriterSettings();
  171. xmlSettings.NewLineChars = "\n";//Environment.NewLine;
  172. xmlSettings.Indent = true;
  173. xmlSettings.CloseOutput = true;
  174. XmlSerializer x_serial = new XmlSerializer( typeof( Workspace ) );
  175. using (XmlWriter wr = XmlWriter.Create( FilePath, xmlSettings )) {
  176. x_serial.Serialize( wr, this );
  177. }
  178. XmlSerializer x_serial_WU = new XmlSerializer( typeof( WorkspaceUserFile ) );
  179. using (XmlWriter wr = XmlWriter.Create( this.WorkspaceUserSetting.FilePath, xmlSettings )) {
  180. x_serial_WU.Serialize( wr, this.WorkspaceUserSetting );
  181. }
  182. /*using (FileStream fs = new FileStream(FilePath, FileMode.Create)) {
  183. XmlSerializer serializer = new XmlSerializer(typeof(Workspace));
  184. serializer.Serialize(fs, this);
  185. }*/
  186. }
  187. public void SaveUserWorkspaceFile(){
  188. if (String.IsNullOrEmpty(FilePath))
  189. return;
  190. XmlWriterSettings xmlSettings = new XmlWriterSettings();
  191. xmlSettings.NewLineChars = "\n";//Environment.NewLine;
  192. xmlSettings.Indent = true;
  193. xmlSettings.CloseOutput = true;
  194. XmlSerializer x_serial_WU = new XmlSerializer( typeof( WorkspaceUserFile ) );
  195. using (XmlWriter wr = XmlWriter.Create( this.WorkspaceUserSetting.FilePath, xmlSettings )) {
  196. x_serial_WU.Serialize( wr, this.WorkspaceUserSetting );
  197. }
  198. }
  199. static void OnExited(object sender, EventArgs e) {
  200. //Console.WriteLine("exit ");
  201. try{
  202. //System.IO.File.Delete(path);
  203. }catch{
  204. }
  205. }
  206. static internal Workspace CreateWorkspace(string filePath, string workspaceName, string workspaceOutput, string workspaceRoot, bool copyLibs)
  207. {
  208. Workspace workspace = new Workspace();
  209. workspace.FilePath = filePath;
  210. workspace.RootDirectory = workspaceRoot;
  211. workspace.OutputDirectory = workspaceOutput;
  212. workspace.Name = workspaceName;
  213. if (!Directory.Exists(workspace.RootDirectory)){
  214. try {
  215. Directory.CreateDirectory(workspace.RootDirectory);
  216. }catch(Exception ex){
  217. throw new Exception(MainClass.Languages.Translate("cannot_create_root",workspace.RootDirectory) + "\n"+ ex.Message);
  218. /*MessageDialogs md =
  219. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("cannot_create_root",workspace.RootDirectory), ex.Message, Gtk.MessageType.Error);
  220. md.ShowDialog();
  221. return null;*/
  222. }
  223. }
  224. if (!Directory.Exists(workspace.OutputMaskToFullPath)){
  225. try {
  226. Directory.CreateDirectory(workspace.OutputMaskToFullPath);
  227. }catch{
  228. }
  229. }
  230. //Console.WriteLine("MainClass.Settings.LibDirectory -> {0}",MainClass.Settings.LibDirectory);
  231. if (!Directory.Exists(MainClass.Settings.LibDirectory)){
  232. throw new Exception(MainClass.Languages.Translate("invalid_lids_dir",MainClass.Settings.LibDirectory) );
  233. /*MessageDialogs md =
  234. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("invalid_lids_dir",MainClass.Settings.LibDirectory),"", Gtk.MessageType.Error);
  235. md.ShowDialog();
  236. return null;*/
  237. }
  238. if (copyLibs)
  239. MainClass.Tools.CopyDirectory(MainClass.Settings.LibDirectory, workspace.RootDirectory, true, true);
  240. else
  241. {
  242. MainClass.Tools.CreateLinks(MainClass.Settings.LibDirectory, workspace.RootDirectory, true, false);
  243. }
  244. workspace.SaveWorkspace();
  245. return workspace;
  246. }
  247. static internal Workspace OpenWorkspace(string filePath){
  248. if (System.IO.File.Exists(filePath))
  249. try {
  250. using (FileStream fs = File.OpenRead(filePath)) {
  251. XmlSerializer serializer = new XmlSerializer(typeof(Workspace));
  252. Workspace w = (Workspace)serializer.Deserialize(fs);
  253. w.FilePath = filePath;
  254. return w;
  255. }
  256. } catch (Exception ex) {
  257. MessageDialogs md =
  258. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("workspace_is_corrupted"), ex.Message, Gtk.MessageType.Error,null);
  259. md.ShowDialog();
  260. return null;
  261. }
  262. else {
  263. //throw new FileNotFoundException();
  264. MessageDialogs md =
  265. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "", MainClass.Languages.Translate("workspace_is_corrupted"), Gtk.MessageType.Error,null);
  266. md.ShowDialog();
  267. return null;
  268. }
  269. }
  270. private static string ShellExec(string cmd,string path,string parms,out int exit_code){
  271. System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(path + cmd, parms);
  272. psi.RedirectStandardOutput = true;
  273. psi.UseShellExecute = false;
  274. System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);
  275. string tool_output = p.StandardOutput.ReadToEnd();
  276. p.WaitForExit();
  277. exit_code = p.ExitCode;
  278. return tool_output;
  279. }
  280. #region Project
  281. public string GetFullPath(string path)
  282. {
  283. if (String.IsNullOrEmpty(path))
  284. return "";
  285. return FileUtility.RelativeToAbsolutePath(RootDirectory, path);
  286. }
  287. public string GetRelativePath(string path)
  288. {
  289. if (String.IsNullOrEmpty(path))
  290. return "";
  291. return FileUtility.AbsoluteToRelativePath(RootDirectory, path);
  292. }
  293. public Project CreateProject(Project prj, AppFile appFile,string skin, string theme,string[] fonts){
  294. string projectLocation = this.RootDirectory;
  295. string projectDir = System.IO.Path.GetFileNameWithoutExtension(prj.FilePath);
  296. Project p = FindProject(prj.FilePath);
  297. if (p == null) {
  298. p = new Project();
  299. if (!System.IO.File.Exists(prj.FilePath)) {
  300. string projectWorkingDir = System.IO.Path.Combine(projectLocation, projectDir);
  301. if (!System.IO.File.Exists(appFile.ApplicationFile)) {
  302. try{
  303. appFile.Save();
  304. } catch(Exception ex){
  305. MessageDialogs ms = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("cannot_save_file", appFile.ApplicationFile), ex.Message, Gtk.MessageType.Error);
  306. ms.ShowDialog();
  307. return null;
  308. }
  309. }
  310. string mainFile = System.IO.Path.Combine(projectWorkingDir,"main.ms");
  311. try {
  312. Directory.CreateDirectory(projectWorkingDir);
  313. using (StreamWriter file = new StreamWriter(mainFile)) {
  314. file.Write("// TODO: Add your code here.");
  315. file.Close();
  316. file.Dispose();
  317. }
  318. //Directory.CreateDirectory(System.IO.Path.Combine(projectWorkingDir, "core"));
  319. //Directory.CreateDirectory(System.IO.Path.Combine(projectWorkingDir, "ui"));
  320. } catch {
  321. }
  322. //p = new Project(prj.FilePath);
  323. prj.NewSkin=true;
  324. //p = new Project(filename);
  325. //p.ProjectDir = GetRelativePath(projectWorkingDir);
  326. //p.ProjectName = projectName;
  327. prj.AppFilePath = GetRelativePath(appFile.ApplicationFile);
  328. prj.StartFile = GetRelativePath(mainFile);
  329. prj.GenerateDevices(skin,theme,fonts);
  330. SaveProject(prj);
  331. Projects.Add(prj);
  332. ProjectsFile.Add(GetRelativePath(prj.FilePath));
  333. return prj;
  334. } else {
  335. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_is_exist",prj.FilePath), "", Gtk.MessageType.Error);
  336. md.ShowDialog();
  337. return null;
  338. }
  339. } else {
  340. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_is_opened",p.ProjectName), null, Gtk.MessageType.Error);
  341. md.ShowDialog();
  342. return null;
  343. }
  344. }
  345. public Project CreateProject(string filename, string projectName, string projectLocation, string projectDir, string aplicationFile,string skin, string theme)
  346. {
  347. Project p = FindProject(filename);
  348. if (p == null) {
  349. p = new Project();
  350. if (!System.IO.File.Exists(filename)) {
  351. string projectWorkingDir = System.IO.Path.Combine(projectLocation, projectDir);
  352. if (!System.IO.File.Exists(aplicationFile)) {
  353. AppFile appFile = new AppFile(aplicationFile, projectName);//, projectDir);
  354. appFile.Uses = "core ui uix uix-skin media sqlite net game2d crypto box2d graphics sensor";
  355. appFile.Main = "main.ms";
  356. appFile.Author = "Generated by Moscrif-Ide";
  357. appFile.Title = projectName;
  358. appFile.Copyright = " ";
  359. appFile.Version = "1.0";
  360. appFile.Orientation = "portrait";
  361. try{
  362. appFile.Save();
  363. } catch(Exception ex){
  364. throw new Exception(MainClass.Languages.Translate("cannot_save_file", appFile.ApplicationFile)+"\n"+ ex.Message);
  365. /*MessageDialogs ms = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("cannot_save_file", appFile.ApplicationFile), ex.Message, Gtk.MessageType.Error);
  366. ms.ShowDialog();
  367. return null;*/
  368. }
  369. }
  370. string mainFile = System.IO.Path.Combine(projectWorkingDir,"main.ms");
  371. try {
  372. Directory.CreateDirectory(projectWorkingDir);
  373. using (StreamWriter file = new StreamWriter(mainFile)) {
  374. file.Write("// TODO: Add your code here.");
  375. file.Close();
  376. file.Dispose();
  377. }
  378. //Directory.CreateDirectory(System.IO.Path.Combine(projectWorkingDir, "core"));
  379. //Directory.CreateDirectory(System.IO.Path.Combine(projectWorkingDir, "ui"));
  380. } catch {
  381. }
  382. p = new Project(filename);
  383. //p.ProjectDir = GetRelativePath(projectWorkingDir);
  384. //p.ProjectName = projectName;
  385. p.AppFilePath = GetRelativePath(aplicationFile);
  386. p.StartFile = GetRelativePath(mainFile);
  387. p.NewSkin=true;
  388. p.GenerateDevices(skin,theme);
  389. SaveProject(p);
  390. Projects.Add(p);
  391. ProjectsFile.Add(GetRelativePath(filename));
  392. LoggingInfo log = new LoggingInfo();
  393. log.LoggWebThread(LoggingInfo.ActionId.IDENewProject,p.ProjectName);
  394. return p;
  395. } else {
  396. throw new Exception(MainClass.Languages.Translate("project_is_exist",filename));
  397. /*MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_is_exist",filename), "", Gtk.MessageType.Error);
  398. md.ShowDialog();
  399. return null;*/
  400. }
  401. } else {
  402. throw new Exception(MainClass.Languages.Translate("project_is_opened",p.ProjectName));
  403. /*MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_is_opened",p.ProjectName), null, Gtk.MessageType.Error);
  404. md.ShowDialog();
  405. return null;*/
  406. }
  407. }
  408. public Project ConvertAppToProject(AppFile aplicationFile)
  409. {
  410. string mspDir = System.IO.Path.GetDirectoryName(aplicationFile.ApplicationFile);
  411. string filename = System.IO.Path.Combine(mspDir, aplicationFile.Name + ".msp");
  412. Project p = FindProject(filename);
  413. if (p == null) {
  414. p = new Project();
  415. if (!System.IO.File.Exists(filename)) {
  416. p = new Project(filename);
  417. //p.ProjectDir = GetRelativePath(projectDir);
  418. //p.ProjectName = aplicationFile.Name;
  419. p.AppFilePath = GetRelativePath(aplicationFile.ApplicationFile);
  420. p.NewSkin=true;
  421. p.GenerateDevices("","");
  422. SaveProject(p);
  423. Projects.Add(p);
  424. ProjectsFile.Add(GetRelativePath(p.FilePath));
  425. return p;
  426. } else {
  427. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_is_exist",filename), "", Gtk.MessageType.Error);
  428. md.ShowDialog();
  429. return null;
  430. }
  431. } else {
  432. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_is_opened", p.ProjectName), null, Gtk.MessageType.Error);
  433. md.ShowDialog();
  434. return null;
  435. }
  436. }
  437. public Project OpenProject(string filename)
  438. {
  439. return OpenProject(filename,true,false);
  440. }
  441. public Project OpenProject(string filename,bool showError,bool throwError)
  442. {
  443. Project p = FindProject(filename);
  444. if (p == null) {
  445. p = Project.OpenProject(filename,showError,throwError);
  446. if (p != null) {
  447. Projects.Add(p);
  448. ProjectsFile.Add(GetRelativePath(p.FilePath));
  449. return p;
  450. }
  451. } else {
  452. if(showError){
  453. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_is_opened", p.ProjectName), null, Gtk.MessageType.Error,null);
  454. md.ShowDialog();
  455. } else if (throwError){
  456. throw new Exception(MainClass.Languages.Translate("project_is_opened", p.ProjectName));
  457. }
  458. return null;
  459. }
  460. return null;
  461. }
  462. public Project CloseProject(string appFile)
  463. {
  464. Project p = FindProject_byApp(appFile, true);
  465. if (p != null) {
  466. Projects.Remove(p);
  467. ProjectsFile.Remove(GetRelativePath(p.FilePath));
  468. SaveProject(p);
  469. return p;
  470. } else {
  471. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("project_not_exit"), null, Gtk.MessageType.Error);
  472. md.ShowDialog();
  473. return null;
  474. }
  475. }
  476. internal Project FindProject(string filename)
  477. {
  478. return Projects.Find(x => x.FilePath == filename);
  479. }
  480. internal Project FindProject_byApp(string appname, bool fullpath)
  481. {
  482. if (fullpath){
  483. //Console.WriteLine("GetRelativePath appname 1->{0}",appname);
  484. appname = GetRelativePath(appname);
  485. //Console.WriteLine("GetRelativePath appname 2->{0}",appname);
  486. }
  487. return Projects.Find(x => x.RelativeAppFilePath == appname);//AppFilePath
  488. }
  489. internal void SaveProject(Project p)
  490. {
  491. try {
  492. /*XmlWriterSettings xmlSettings = new XmlWriterSettings();
  493. xmlSettings.NewLineChars = "\n";//Environment.NewLine;
  494. xmlSettings.Indent = true;
  495. xmlSettings.CloseOutput = true;
  496. XmlSerializer x_serial = new XmlSerializer( typeof( Project ) );
  497. using (XmlWriter wr = XmlWriter.Create( p.FilePath, xmlSettings )) {
  498. x_serial.Serialize( wr, p );
  499. }
  500. XmlSerializer x_serial_PU = new XmlSerializer( typeof( ProjectUserFile ) );
  501. using (XmlWriter wr = XmlWriter.Create( p.ProjectUserSetting.FilePath, xmlSettings )) {
  502. x_serial_PU.Serialize( wr, p.ProjectUserSetting );
  503. }*/
  504. p.Save();
  505. } catch (Exception ex) {
  506. MessageDialogs md =
  507. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("error_saving"), ex.Message, Gtk.MessageType.Error);
  508. md.ShowDialog();
  509. }
  510. }
  511. public bool RenameProject(Project prj, string newName){
  512. string newDir = System.IO.Path.Combine(MainClass.Workspace.RootDirectory,newName);
  513. string newApp = System.IO.Path.Combine(MainClass.Workspace.RootDirectory,newName+".app");
  514. string newPrj = System.IO.Path.Combine(MainClass.Workspace.RootDirectory,newName+".msp");
  515. string oldPrjName =prj.ProjectName;
  516. if(File.Exists(newApp) || File.Exists(newPrj) || Directory.Exists(newDir)){
  517. MessageDialogs md =
  518. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("cannot_rename_project",prj.ProjectName),MainClass.Languages.Translate("project_exist"), Gtk.MessageType.Error);
  519. md.ShowDialog();
  520. return false;
  521. }
  522. string oldPrjFile =prj.FilePath;
  523. System.IO.File.Move(prj.AbsolutAppFilePath, newApp);
  524. System.IO.File.Move(prj.FilePath ,newPrj);
  525. System.IO.Directory.Move(prj.AbsolutProjectDir,newDir);
  526. prj.AppFilePath = GetRelativePath(newApp);
  527. prj.FilePath =newPrj;
  528. foreach(FileItem fi in prj.FilesProperty){
  529. fi.FilePath = fi.FilePath.Replace("./"+oldPrjName+"/","./"+newName+"/");
  530. fi.FilePath = fi.FilePath.Replace(".\\"+oldPrjName+"\\",".\\"+newName+"\\");
  531. //MainClass.Workspace.GetRelativePath(d.FullName);
  532. }
  533. SaveProject(prj);
  534. ProjectsFile.Remove(GetRelativePath(oldPrjFile));
  535. ProjectsFile.Add(GetRelativePath(prj.FilePath));
  536. Devices.Device dev = prj.DevicesSettings.Find(x=>x.Devicetype == DeviceType.iOS_5_0);
  537. if(dev != null){
  538. Devices.PublishProperty pp = dev.PublishPropertisMask.Find(x=>x.PublishName == Project.KEY_BUNDLEIDENTIFIER);
  539. if(pp != null)
  540. pp.PublishValue.Replace(oldPrjName,newName);
  541. }
  542. return true;
  543. }
  544. #endregion
  545. #region File/Directory
  546. public TypeFile? ToggleExcludeFile(string filename, string appFile)
  547. {
  548. if (String.IsNullOrEmpty(appFile))
  549. return null;
  550. Project prj = FindProject_byApp(appFile, true);
  551. if (prj == null)
  552. return null;
  553. string relativeFile = GetRelativePath(filename);
  554. FileItem fi = prj.ToggleExcludeFile(relativeFile);
  555. if (fi.IsExcluded)
  556. return TypeFile.ExcludetFile;
  557. else
  558. return TypeFile.SourceFile;
  559. /*
  560. FileItem fi = prj.ExcludesFiles.Find(x => x.FilePath == relativeFile);
  561. if (fi == null) {
  562. prj.ExcludesFiles.Add(new FileItem(relativeFile, true));
  563. return TypeFile.ExcludetFile;
  564. } else {
  565. prj.ExcludesFiles.Remove(fi);
  566. return TypeFile.SourceFile;
  567. }*/
  568. }
  569. public void SetAsStartup(string filename, string appFilePath)
  570. {
  571. if (String.IsNullOrEmpty(appFilePath))
  572. return;
  573. Project prj = FindProject_byApp(appFilePath, true);
  574. if (prj == null)
  575. return;
  576. if (!String.IsNullOrEmpty(filename)) {
  577. if (!String.IsNullOrEmpty(prj.StartFile)) {
  578. // change old file
  579. Gtk.TreeIter tiOld = MainClass.MainWindow.WorkspaceTree.GetStartUpIter(GetFullPath(prj.StartFile));
  580. MainClass.MainWindow.WorkspaceTree.UpdateIter(tiOld, String.Empty, String.Empty, (int)TypeFile.SourceFile);
  581. }
  582. AppFile appFile = prj.AppFile;
  583. appFile.Main = System.IO.Path.GetFileName(filename);
  584. try{
  585. appFile.Save();
  586. } catch(Exception ex){
  587. MessageDialogs ms = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("cannot_save_file", appFile.ApplicationFile), ex.Message, Gtk.MessageType.Error);
  588. ms.ShowDialog();
  589. }
  590. //prj.AppFile.Main = System.IO.Path.GetFileName(filename);
  591. //prj.AppFile.Save();
  592. }
  593. prj.StartFile = GetRelativePath(filename);
  594. SaveProject(prj);
  595. }
  596. public string AddDirectory(string dirPath, string selectedDir, int selectedTyp)
  597. {
  598. //string filename = System.IO.Path.GetFileName(Filename);
  599. string dirName = System.IO.Path.GetFileName(dirPath);
  600. string newPath = "";
  601. if (selectedTyp == (int)TypeFile.AppFile) {
  602. Project prj = FindProject_byApp(selectedDir, true);
  603. if (prj == null)
  604. return String.Empty;
  605. selectedDir = prj.AbsolutProjectDir;
  606. newPath = System.IO.Path.Combine(prj.AbsolutProjectDir, dirName);
  607. } else
  608. newPath = System.IO.Path.Combine(selectedDir, dirName);
  609. if (System.IO.File.Exists(newPath))
  610. newPath = System.IO.Path.Combine(selectedDir, "Copy_" + dirName);
  611. try {
  612. MainClass.Tools.CopyDirectory(dirPath, newPath, true, true);
  613. } catch {
  614. return String.Empty;
  615. }
  616. return newPath;
  617. }
  618. public string AddTheme(string selectedProj, int selectedTyp)
  619. {
  620. string themeName = null;
  621. if (selectedTyp != (int)TypeFile.AppFile)
  622. return null;
  623. Project prj = FindProject_byApp(selectedProj, true);
  624. if (prj == null)
  625. return String.Empty;
  626. CreateThemeDialog ctd = new CreateThemeDialog(prj);
  627. int result = ctd.Run();
  628. if (result == (int)Gtk.ResponseType.Ok) {
  629. themeName = ctd.ThemePath;
  630. string skinName = ctd.SkinPath;
  631. try {
  632. MainClass.Tools.CopyDirectory(skinName, themeName, true, true);
  633. } catch {
  634. themeName = null;
  635. }
  636. }
  637. ctd.Destroy();
  638. return themeName;
  639. }
  640. public string AddFile(string filePath, string selectedDir, int selectedTyp)
  641. {
  642. string filename = System.IO.Path.GetFileName(filePath);
  643. string newFile = "";
  644. if (selectedTyp == (int)TypeFile.AppFile) {
  645. Project prj = FindProject_byApp(selectedDir, true);
  646. if (prj == null)
  647. return String.Empty;
  648. newFile = System.IO.Path.Combine(prj.AbsolutProjectDir, filename);
  649. selectedDir = prj.AbsolutProjectDir;
  650. } else
  651. newFile = System.IO.Path.Combine(selectedDir, filename);
  652. if (System.IO.File.Exists(newFile))
  653. newFile = System.IO.Path.Combine(selectedDir, "Copy_" + filename);
  654. try {
  655. System.IO.File.Copy(filePath, newFile);
  656. } catch {
  657. return String.Empty;
  658. }
  659. return newFile;
  660. }
  661. public string CreateFile(string filename, string selectedDir, int selectedTyp,string content)
  662. {
  663. //string filename = System.IO.Path.GetFileName(Filename);
  664. string newFile = "";
  665. if (selectedTyp == (int)TypeFile.AppFile) {
  666. Project prj = FindProject_byApp(selectedDir, true);
  667. if (prj == null)
  668. return String.Empty;
  669. selectedDir = prj.AbsolutProjectDir;
  670. }
  671. if(Directory.Exists(selectedDir))
  672. newFile = System.IO.Path.Combine(selectedDir, filename);
  673. else return String.Empty;
  674. try {
  675. FileUtility.CreateFile(newFile,content); //CreateDirectory(newFile);
  676. } catch {
  677. MessageDialogs md =
  678. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("error_creating_file"), filename, Gtk.MessageType.Error);
  679. md.ShowDialog();
  680. return String.Empty;
  681. }
  682. return newFile;
  683. }
  684. public string CreateDirectory(string Filename, string selectedDir, int selectedTyp)
  685. {
  686. string filename = System.IO.Path.GetFileName(Filename);
  687. string newFile = "";
  688. if (selectedTyp == (int)TypeFile.AppFile) {
  689. Project prj = FindProject_byApp(selectedDir, true);
  690. if (prj == null)
  691. return String.Empty;
  692. newFile = System.IO.Path.Combine(prj.AbsolutProjectDir, filename);
  693. selectedDir = prj.AbsolutProjectDir;
  694. } else
  695. newFile = System.IO.Path.Combine(selectedDir, filename);
  696. try {
  697. FileUtility.CreateDirectory(newFile);
  698. } catch {
  699. MessageDialogs md =
  700. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("error_creating_dir"), filename, Gtk.MessageType.Error);
  701. md.ShowDialog();
  702. return String.Empty;
  703. }
  704. return newFile;
  705. }
  706. /*public void DeleteFile()
  707. {
  708. string filename = "";
  709. int typ = -1;
  710. Gtk.TreeIter ti = new Gtk.TreeIter();
  711. MainClass.MainWindow.WorkspaceTree.GetSelectedFile(out filename, out typ, out ti);
  712. if (typ == (int)TypeFile.Directory) {
  713. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, string.Format("Are you sure you want to permanently delete folder {0} ?", filename), "", Gtk.MessageType.Question);
  714. int result = md.ShowDialog();
  715. if (result != (int)Gtk.ResponseType.Yes)
  716. return;
  717. if (!System.IO.Directory.Exists(filename))
  718. return;
  719. try {
  720. System.IO.Directory.Delete(filename, true);
  721. } catch {
  722. MessageDialogs mdd =
  723. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "Cannot delete File.",filename, Gtk.MessageType.Error);
  724. mdd.ShowDialog();
  725. }
  726. } else {
  727. MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, string.Format("Are you sure you want to permanent delete file {0} ?", filename), "", Gtk.MessageType.Question);
  728. int result = md.ShowDialog();
  729. if (result != (int)Gtk.ResponseType.Yes)
  730. return;
  731. if (!System.IO.File.Exists(filename))
  732. return;
  733. try {
  734. System.IO.File.Delete(filename);
  735. } catch {
  736. MessageDialogs mdd =
  737. new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "Cannot rename File.", filename, Gtk.MessageType.Error);
  738. mdd.ShowDialog();
  739. }
  740. }
  741. if (typ == (int)TypeFile.StartFile) {
  742. string appFile = MainClass.MainWindow.WorkspaceTree.GetSelectedProjectApp();
  743. if (String.IsNullOrEmpty(appFile))
  744. return;
  745. Project prj = FindProject_byApp(appFile, true);
  746. if (prj != null)
  747. prj.StartFile = String.Empty;
  748. }
  749. MainClass.MainWindow.WorkspaceTree.RemoveTree(ti);
  750. }
  751. */
  752. #endregion
  753. }
  754. }