Example #1
0
        private Project ImportProject(string appPath, string projectName, string newLibs, string newOrientation)
        {
            //TreeIter ti =  AddMessage("Create Project ","....",null);
            if (entrPage2PrjName.Text == prjDefaultName)
            {
                MainClass.Settings.ProjectCount = MainClass.Settings.ProjectCount + 1;
            }

            string oldName = System.IO.Path.GetFileNameWithoutExtension(appPath);

            if (String.IsNullOrEmpty(MainClass.Workspace.FilePath))
            {
                return(null);
            }

            string destinationDir = System.IO.Path.GetDirectoryName(appPath);             // aka workspace from
            string projectDir     = System.IO.Path.Combine(destinationDir, oldName);      // aka project dir from

            string mspPath = System.IO.Path.Combine(destinationDir, oldName + ".msp");

            if (!File.Exists(appPath) || !File.Exists(mspPath))
            {
                AddMessage(MainClass.Languages.Translate("wizzard_create_project"), MainClass.Languages.Translate("invalid_zip"), null);
                //UpdateMessage(ti,1,MainClass.Languages.Translate("invalid_zip"));
                return(null);
            }
            if (!System.IO.Directory.Exists(projectDir))
            {
                AddMessage(MainClass.Languages.Translate("wizzard_create_project"), MainClass.Languages.Translate("invalid_project"), null);
                //UpdateMessage(ti,1,MainClass.Languages.Translate("invalid_project"));
                return(null);
            }

            string newApp = System.IO.Path.Combine(MainClass.Workspace.RootDirectory, projectName + ".app");
            string newMsp = System.IO.Path.Combine(MainClass.Workspace.RootDirectory, projectName + ".msp");

            if (File.Exists(newApp) || File.Exists(newMsp))
            {
                AddMessage(MainClass.Languages.Translate("wizzard_create_project"), MainClass.Languages.Translate("project_exist"), null);

                //UpdateMessage(ti,1,MainClass.Languages.Translate("project_exist"));
                return(null);
            }

            FileInfo     fi = new FileInfo(appPath);
            FileTemplate ft = new FileTemplate(fi, false);

            atrApplication.Value = projectName;
            ft.Attributes.Add(atrApplication);

            string contentApp = FileTemplateUtilities.Apply(ft.Content, ft.GetAttributesAsDictionary());

            string contentMsp = "";

            if (System.IO.File.Exists(mspPath))
            {
                try {
                    using (StreamReader file = new StreamReader(mspPath)) {
                        string text = file.ReadToEnd();
                        contentMsp = text;
                    }
                } catch {
                }
            }
            contentMsp = Regex.Replace(contentMsp, oldName, System.IO.Path.GetFileNameWithoutExtension(newApp));

            Project prj = null;

            try {
                FileUtility.CreateFile(newApp, contentApp);
                AppFile app = null;
                if (!String.IsNullOrEmpty(newLibs))
                {
                    app             = new AppFile(newApp);
                    app.Uses        = newLibs;
                    app.Orientation = newOrientation;
                    app.Save();
                }

                FileUtility.CreateFile(newMsp, contentMsp);

                string newPrjDir = System.IO.Path.Combine(MainClass.Workspace.RootDirectory, projectName);

                TreeIter ti = AddMessage(MainClass.Languages.Translate("wizzard_copying"), "....", null);

                MainClass.Tools.CopyDirectory(projectDir, newPrjDir, true, true);
                //string[] dirNew = System.IO.Directory.GetDirectories(newPrjDir,"*.*",SearchOption.AllDirectories);

                string[] filesNew = System.IO.Directory.GetFiles(newPrjDir, "*.ms", SearchOption.AllDirectories);
                foreach (string file in filesNew)
                {
                    FileInfo     fiNew = new FileInfo(file);
                    FileTemplate ftNew = new FileTemplate(fiNew, false);
                    atrApplication.Value = projectName;
                    ftNew.Attributes.Add(atrApplication);

                    string contentNew = FileTemplateUtilities.Apply(ftNew.Content, ftNew.GetAttributesAsDictionary());

                    try{
                        using (StreamWriter fileSW = new StreamWriter(file)) {
                            fileSW.Write(contentNew);
                            fileSW.Close();
                            fileSW.Dispose();
                        }
                    }catch (Exception ex) {
                        Tool.Logger.Error(ex.Message);
                        continue;
                    }
                }
                UpdateMessage(ti, 1, "OK");

                prj = MainClass.Workspace.OpenProject(newMsp, false, true);               //Project.OpenProject(newMsp,false,true);

                LoggingInfo log = new LoggingInfo();
                log.LoggWebThread(LoggingInfo.ActionId.IDENewProject, prj.ProjectName);
            } catch {
                AddMessage(MainClass.Languages.Translate("wizzard_create_project"), MainClass.Languages.Translate("error_creating_project"), null);
                //UpdateMessage(ti,1,MainClass.Languages.Translate("error_creating_project"));
                return(null);
            }
            AddMessage(MainClass.Languages.Translate("wizzard_create_project"), "OK", null);
            //UpdateMessage(ti,1,"OK");
            return(prj);
        }
Example #2
0
        //int pageCount = 1;
        protected virtual void OnButtonOkClicked(object sender, System.EventArgs e)
        {
            if (notebook1.Page == 0)
            {
                btnBack.Sensitive = true;

                TreeSelection ts = tvItem.Selection;
                TreeIter      ti = new TreeIter();
                ts.GetSelected(out ti);

                TreePath[] tp = ts.GetSelectedRows();

                fileName = entrName.Text;

                if (tp.Length <= 0)
                {
                    return;
                }
                if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                fileExtension = tvItem.Model.GetValue(ti, 1).ToString();

                notebook1.Page = 1;
                //pageCount =2;
                entrName2.Text = entrName.Text;
                //}
            }
            else if (notebook1.Page == 1)
            {
                FileTemplate ft = GetSelectedTemplate();

                lblPrjName.LabelProp = FileName;
                Pango.FontDescription customFont = lblPrjName.Style.FontDescription.Copy();                //  Pango.FontDescription.FromString(MainClass.Settings.ConsoleTaskFont);
                customFont.Size   = customFont.Size + (customFont.Size / 2);
                customFont.Weight = Pango.Weight.Bold;
                lblPrjName.ModifyFont(customFont);


                if (ft == null)
                {
                    content = "";
                    this.Respond(ResponseType.Ok);
                    return;
                }
                while (tblAtributes.Children.Length > 0)
                {
                    tblAtributes.Remove(tblAtributes.Children[0]);
                }

                tblAtributes.NRows        = (uint)ft.Attributes.Count + 3;
                tblAtributes.NColumns     = 3;
                tblAtributes.BorderWidth  = 10;
                tblAtributes.WidthRequest = 200;
                //tblAtributes.BorderWidth = 2;

                //vbox3.PackStart(tblAtributes,true,true,2);
                int i = 1;
                foreach (FileTemplate.Attribute attr in ft.Attributes)
                {
                    if (attr.Type == "bool")
                    {
                        bool defValue = false;
                        if (attr.Value != null)
                        {
                            Boolean.TryParse(attr.Value.ToString(), out defValue);
                        }
                        GenerateCheckBox(ref tblAtributes, attr, i);
                    }
                    else
                    {
                        GenerateEntry(ref tblAtributes, attr, i);
                    }
                    i++;
                }
                ;
                tblAtributes.ShowAll();
                this.ShowAll();
                notebook1.Page = 2;
                //pageCount =3;
            }
            else if (notebook1.Page == 2)
            {
                FileTemplate ft = GetSelectedTemplate();
                fileTemplate = ft;
                if (ft == null)
                {
                    content = "";
                }
                else
                {
                    content = FileTemplateUtilities.Apply(fileTemplate.Content, fileTemplate.GetAttributesAsDictionary());
                }
                this.Respond(ResponseType.Ok);
            }
        }