示例#1
0
        public bool ExecuteTask()
        {
            if (MainClass.Workspace.ActualProject == null) {
                SetError(MainClass.Languages.Translate("no_project_selected"));
                return false;
            }

            project = MainClass.Workspace.ActualProject;

            if (String.IsNullOrEmpty(project.ProjectOutput)){

                if (!String.IsNullOrEmpty(MainClass.Workspace.OutputDirectory)){
                    project.ProjectOutput  = MainClass.Workspace.OutputDirectory;

                } else project.ProjectOutput  = project.AbsolutProjectDir;
            }

            if(!Directory.Exists(project.OutputMaskToFullPath)){
                try{
                    Directory.CreateDirectory(project.OutputMaskToFullPath);
                }catch
                {
                    SetError(MainClass.Languages.Translate("cannot_create_output"));
                return false;
                }
            }

            stateTask = StateEnum.OK;

            //################ uvodne kontroly
            if (MainClass.MainWindow.RunningEmulator) {
                SetError(MainClass.Languages.Translate("emulator_is_running"));
                return false;
            }

            string cmd = Path.Combine(MainClass.Settings.EmulatorDirectory, "moscrif.exe");

            if(MainClass.Platform.IsMac){
                //Console.WriteLine("EmulatorDirectory --> {0}",MainClass.Settings.EmulatorDirectory);

                //cmd = "open";// + MainClass.Settings.EmulatorDirectory,  "moscrif.app");
                string file = System.IO.Path.Combine( MainClass.Settings.EmulatorDirectory,  "Moscrif.app");//.app
                file = System.IO.Path.Combine(file,  "Contents");
                file = System.IO.Path.Combine(file,  "MacOS");
                file = System.IO.Path.Combine(file,  "Moscrif");
                cmd = file;
                Tool.Logger.LogDebugInfo(String.Format("command compile MAC ->{0}",cmd),null);
            }

            if(MainClass.Platform.IsWindows){

                if (!System.IO.File.Exists(cmd)) {
                    SetError(MainClass.Languages.Translate("emulator_not_found"));
                    return false;
                }
            }

            string tempDir =  MainClass.Paths.TempPublishDir;//System.IO.Path.Combine(MainClass.Settings.PublishDirectory,"_temp");

            if (!Directory.Exists(tempDir)){

                try{
                    Directory.CreateDirectory(tempDir);
                } catch{
                    SetError(MainClass.Languages.Translate("cannot_create_temp_f1"));
                    return false;
                }
            }

            if ((listCombinePublish == null) || (listCombinePublish.Count <1)){
                SetError(MainClass.Languages.Translate("publish_list_is_empty"));
                return false;
                //project.GeneratePublishCombination();
            }

            bool cancelled = false;
            bool isAndroid = false;

            foreach(CombinePublish ccc in  listCombinePublish){
                CombineCondition crPlatform = ccc.combineRule.Find(x=>x.ConditionId==MainClass.Settings.Platform.Id);
                if(crPlatform != null){

                    if ((crPlatform.RuleId == (int)DeviceType.Android_1_6)||
                        (crPlatform.RuleId == (int)DeviceType.Android_2_2)){
                        Console.WriteLine("ANDROID FOUND");
                        CheckJava();
                    }
                }
            }

            if(!isJavaInstaled && isAndroid){
                MessageDialogsUrl md = new MessageDialogsUrl(MessageDialogsUrl.DialogButtonType.Ok,MainClass.Languages.Translate("java_missing"), MainClass.Languages.Translate("java_missing_title"),"http://moscrif.com/java-requirement", Gtk.MessageType.Error,ParentWindow);
                md.ShowDialog();
            }

            project = MainClass.Workspace.ActualProject;

            if((MainClass.User == null) || (string.IsNullOrEmpty(MainClass.User.Token))){
                SetError(MainClass.Languages.Translate("invalid_login"));
                return false;
            }

            //########################## kompilovanie
            progressDialog = new ProgressDialog(MainClass.Languages.Translate("compiling"),ProgressDialog.CancelButtonType.None,listCombinePublish.Count,ParentWindow);//MainClass.MainWindow		//#################### kompilovanie
            try {
                List<string> list = new List<string>();

                GetComands(project.AbsolutProjectDir, ref list,true);
                string[] libs = project.AppFile.Libs;

                foreach (string lib in libs){
                    if(string.IsNullOrEmpty(lib)) continue;
                    string pathLib = System.IO.Path.Combine(MainClass.Workspace.RootDirectory,lib);
                    GetComands(pathLib, ref list,true);
                }

                if (list.Count > 0) {
                    double step = 1 / (list.Count * 1.0);
                        MainClass.MainWindow.ProgressStart(step, MainClass.Languages.Translate("compiling"));
                    progressDialog.Reset(list.Count,MainClass.Languages.Translate("compiling"));
                }

                foreach (string f in list) {
                    if (exitCompile) { // chyba koncim
                        MainClass.MainWindow.ProgressEnd();
                        progressDialog.Destroy();

                        SetError(MainClass.Languages.Translate("compiling_failed"));
                        return false;
                    }

                    string fileUpdate = FileUtility.AbsoluteToRelativePath(MainClass.Workspace.RootDirectory ,f);

                    if ( project.FilesProperty != null){

                        FileItem fi =  project.FilesProperty.Find(x => x.SystemFilePath == fileUpdate);
                        if (fi != null)
                        {
                            if (fi.IsExcluded) continue;
                        }
                    }

                    string fdir = System.IO.Path.GetDirectoryName(f);
                    string fname = System.IO.Path.GetFileName(f);

                    string args = String.Format("/d \"{0}\" /c {1} /o console", fdir, fname);

                    if(MainClass.Platform.IsMac){

                        args = String.Format("-d {0} -c {1} -o console", fdir, fname);

                            /*Process []pArry = Process.GetProcesses();
                            foreach(Process p in pArry)
                            {
                                if(p != null){
                                    try {
                                        if(p.ProcessName == "Moscrif"){
                                            p.Kill();
                                            MainClass.MainWindow.RunningEmulator= false;
                                        }
                                        //string s = p.ProcessName;
                                        //s = s.ToLower();
                                        //Console.WriteLine("\t"+s);
                                    } catch (Exception ex){
                                        Console.WriteLine(ex.Message);
                                    }
                                }
                            }*/
                    }

                    string a = args;
                    //output.Add(new TaskMessage("args>>" + a));

                    ProcessService ps = new ProcessService();

                    MainClass.MainWindow.ProgressStep();
                    progressDialog.Update(f);

                    ProcessWrapper pw = ps.StartProcess(cmd, a, fdir, ProcessOutputChange, ProcessOutputChange);
                    pw.WaitForExit();
                    //pw.WaitForOutput();

                    pw.Exited += delegate(object sender, EventArgs e) {
                        //Console.WriteLine("pw.Exited");
                        ParseOutput(MainClass.Languages.Translate("exit_compiling"),pw.StartInfo.WorkingDirectory);
                    };

                }

            } catch (Exception ex) {
                MainClass.MainWindow.ProgressEnd();
                progressDialog.Destroy();
                SetError(MainClass.Languages.Translate("compiling_failed"),ex.Message);

                return false;
            } finally {
            }

            if(stateTask != StateEnum.OK){

                MainClass.MainWindow.ProgressEnd();
                progressDialog.Destroy();

                SetError(MainClass.Languages.Translate("compiling_failed"));

                return false;
            }

            //#################### regenerate app file, backup, hash
            parentTask = new TaskMessage("OK",MainClass.Languages.Translate("compiling"),null);
            output.Add(parentTask);

            List<string> filesList = new List<string>();
            GetAllFiles(ref filesList,project.AbsolutProjectDir );

            progressDialog.Reset(filesList.Count,MainClass.Languages.Translate("generate_app"));

            string bakAppPath =project.AbsolutAppFilePath+".bak";
            string hashAppPath =project.AbsolutAppFilePath+".hash";

            if(System.IO.File.Exists(bakAppPath)){
                try{
                    File.Delete(bakAppPath);
                } catch {
                    progressDialog.Destroy();
                    SetError(MainClass.Languages.Translate("cannot_create_backup"));

                    return false;
                }
            }
            if(System.IO.File.Exists(hashAppPath)){
                try{
                    File.Delete(hashAppPath);
                } catch {
                    progressDialog.Destroy();
                    SetError(MainClass.Languages.Translate("cannot_create_hash"));
                    return false;
                }
            }

            try{
                File.Copy(project.AbsolutAppFilePath,bakAppPath);
                File.Copy(project.AbsolutAppFilePath,hashAppPath);
            } catch {
                progressDialog.Destroy();
                SetError(MainClass.Languages.Translate("cannot_create_backup"));
                return false;
            }

            using (StreamWriter stream = File.AppendText(hashAppPath)) {
                stream.WriteLine();

                foreach(string file in filesList){

                    if (System.IO.Path.GetExtension(file)==".ms") continue;

                    string fileUpdate = FileUtility.AbsoluteToRelativePath(project.AbsolutProjectDir,file);
                    fileUpdate = FileUtility.TrimStartingDotCharacter(fileUpdate);
                    fileUpdate = FileUtility.TrimStartingDirectorySeparator(fileUpdate);
            /*
                    stream.WriteLine("file : {0}",fileUpdate);

                    string fileNameHash = Cryptographer.SHA1HashBase64(fileUpdate);
                    stream.WriteLine("hash : {0}",fileNameHash);
                    */
                    progressDialog.Update(MainClass.Languages.Translate("create_app"));
                    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) {
                        int size = (int)fs.Length;
                        byte[] data = new byte[size];
                        fs.Read(data, 0, size);
                        fs.Close();
                        stream.WriteLine("file: {0}",fileUpdate);
                        stream.WriteLine("hash: {0}", Cryptographer.SHA1HashBase64(data));
                    }
                }

                stream.Flush();
                stream.Close();
                stream.Dispose();
            }

            //#################### podpisovanie

            progressDialog.Reset(0,MainClass.Languages.Translate("sign_app_f1"));
            progressDialog.SetLabel (MainClass.Languages.Translate("sign_app_f1") );

            SignApp sa = new SignApp();
            string newAppdata = "";

            try{
                if(!sa.PostFile(hashAppPath,MainClass.User.Token,out newAppdata)){
                    //timer.Stop();
                    progressDialog.Destroy();
                    RestoreBackup(hashAppPath,bakAppPath);

                    //SetError(MainClass.Languages.Translate("expired_licence"),newAppdata);
                    output.Add(new TaskMessage(newAppdata,MainClass.Languages.Translate("expired_licence"),null));
                    stateTask = StateEnum.ERROR;

                    LicenceExpiredDialog md = new LicenceExpiredDialog(MainClass.Languages.Translate("expired_licence"));
                    md.Run();
                    md.Destroy();
                    return false;
                }

                if(String.IsNullOrEmpty(newAppdata)){
                    //timer.Stop();
                    progressDialog.Destroy();
                    RestoreBackup(hashAppPath,bakAppPath);
                    SetError(MainClass.Languages.Translate("sign_app_failed"));
                    return false;
                }

                using (StreamWriter file = new StreamWriter(project.AbsolutAppFilePath)) {
                    file.Write(newAppdata);
                    file.Flush();
                    file.Close();
                }

            }catch(Exception ex){
                //timer.Stop();
                progressDialog.Destroy();

                SetError(MainClass.Languages.Translate("sign_app_failed"), ex.Message);
                //Console.WriteLine(ex.Message);
                RestoreBackup(hashAppPath,bakAppPath);
                return false;
            }

            //timer.Stop();
            parentTask = new TaskMessage("OK",MainClass.Languages.Translate("sign"),null);
            output.Add(parentTask);

            //#################### publish
            //if (listCombinePublish.Count > 0) {
                //List<CombinePublish> lst =project.CombinePublish.FindAll(x=>x.IsSelected==true);
                double step2 = 1 / (listCombinePublish.Count * 1.0);
                MainClass.MainWindow.ProgressStart(step2, MainClass.Languages.Translate("publish"));
                //progressDialog = new ProgressDialog(MainClass.Languages.Translate("publishing"),ProgressDialog.CancelButtonType.Cancel,listCombinePublish.Count,MainClass.MainWindow);
                progressDialog.Reset(listCombinePublish.Count,MainClass.Languages.Translate("publishing"));
            //}

            foreach(CombinePublish ccc in  listCombinePublish){//listCC ){
                //if (!ccc.IsSelected) continue;
                //Console.WriteLine(ccc.ToString());

                if (cancelled) break;

                if(String.IsNullOrEmpty(project.ProjectArtefac) ){
                    project.ProjectArtefac = System.IO.Path.GetFileNameWithoutExtension(project.RelativeAppFilePath);
                }
                string fileName =  project.ProjectArtefac;

                List<ConditionDevice> condList = new List<ConditionDevice>();

                foreach(CombineCondition cr in ccc.combineRule){
                    ConditionDevice cd = new ConditionDevice (cr.ConditionName,cr.RuleName);
                    //condList.Add(new ConditionDevice(cr.ConditionName,cr.RuleName));
                    if(cr.ConditionId == MainClass.Settings.Resolution.Id){
                        Rule rl = MainClass.Settings.Resolution.Rules.Find(x=>x.Id == cr.RuleId);
                        if(rl!= null){
                            cd.Height = rl.Height;
                            cd.Width = rl.Width;
                        }

                    }
                    condList.Add(cd);

                    fileName = fileName.Replace(String.Format("$({0})",cr.ConditionName),cr.RuleName);
                }

                parentTask = new TaskMessage(MainClass.Languages.Translate("publishing"),fileName,null);
                devicePublishError = false;

                if (progressDialog != null)
                     progressDialog.SetLabel (fileName );

                if (Directory.Exists(tempDir)) {
                    try{
                        DirectoryInfo di = new DirectoryInfo(tempDir);
                        foreach (DirectoryInfo d in di.GetDirectories()){
                            d.Delete(true);
                        }
                        foreach (FileInfo f in di.GetFiles()){
                            f.Delete();
                        }

                    } catch {
                    }
                }

                CombineCondition crPlatform = ccc.combineRule.Find(x=>x.ConditionId==MainClass.Settings.Platform.Id);
                CombineCondition crRsolution = ccc.combineRule.Find(x=>x.ConditionId==MainClass.Settings.Resolution.Id);

                if (crPlatform == null) {
                    SetError(MainClass.Languages.Translate("platform_not_found", MainClass.Settings.Platform.Name), parentTask);
                    continue;
                }

                Device dvc = project.DevicesSettings.Find(x=>x.TargetPlatformId == crPlatform.RuleId);

                if (dvc == null) {
                    SetError(MainClass.Languages.Translate("device_not_found", crPlatform.ConditionName, crPlatform.RuleName), parentTask);
                    continue;
                }

                //if ((crPlatform.RuleId == (int)DeviceType.Android_1_6) && (!isJavaInstaled)){
                if (((crPlatform.RuleId == (int)DeviceType.Android_1_6) ||
                  (crPlatform.RuleId == (int)DeviceType.Android_2_2))
                    && (!isJavaInstaled)){
                    SetError(MainClass.Languages.Translate("java_missing"), parentTask);
                    continue;
                }

                string dirPublish = MainClass.Tools.GetPublishDirectory(dvc.Platform.Specific);//System.IO.Path.Combine(MainClass.Settings.PublishDirectory,dvc.Platform.Specific);//crPlatform.RuleName);

                if (!Directory.Exists(dirPublish)){
                    SetError(MainClass.Languages.Translate("publish_tool_not_found"), parentTask);
                    continue;
                }

                if (String.IsNullOrEmpty(dirPublish)) {

                    SetError(MainClass.Languages.Translate("publish_tool_not_found_f1"), parentTask);
                    continue;
                }

                dvc.Application = project.AppFile.Name;

                if (String.IsNullOrEmpty(project.ProjectOutput)){

                    if (!String.IsNullOrEmpty(MainClass.Workspace.OutputDirectory)){

                        project.ProjectOutput  = MainClass.Workspace.OutputDirectory;

                    } else project.ProjectOutput  = project.AbsolutProjectDir;
                }

                dvc.Output_Dir = project.OutputMaskToFullPath;

                dvc.Temp = tempDir;

                dvc.Temp = LastSeparator(dvc.Temp);
                dvc.Publish = LastSeparator(MainClass.Settings.PublishDirectory);
                dvc.Root = LastSeparator(MainClass.Workspace.RootDirectory);
                dvc.Output_Dir = LastSeparator(dvc.Output_Dir);
                dvc.Conditions =condList.ToArray();

                List<int> mergeResolutions = new List<int>();
                string resolution = crRsolution.RuleName;
                mergeResolutions.Add(crRsolution.RuleId);

                // Ak je zaskrtnute Merge All Resolution
                // Najdem vsetky publishovatelne combinacie danej platformy (napr. vsetky publishovane andrroidy)
                // a vytiahnem z nich rezolution a spojim do do string odeleneho &
                if(dvc.Includes.Skin != null){
                    dvc.Includes.Skin.ResolutionJson = dvc.Includes.Skin.Resolution;
                    if(!String.IsNullOrEmpty(dvc.Includes.Skin.Name)){
                        if(project.IncludeAllResolution){
                            resolution = "";
                            foreach(CombinePublish cp in  listCombinePublish){
                                CombineCondition crPlatform2 = cp.combineRule.Find(x=>x.ConditionId==MainClass.Settings.Platform.Id && x.RuleId== crPlatform.RuleId);
                                if(crPlatform2 != null){
                                    CombineCondition crResolution2 = cp.combineRule.Find(x=>x.ConditionId==MainClass.Settings.Resolution.Id );
                                    if(crResolution2!= null){
                                        resolution =resolution+crResolution2.RuleName+"&";
                                    }
                                }

                            }
                            resolution = resolution.Remove(resolution.Length - 1, 1);
                            ConditionDevice cd = condList.Find(x=>x.Name == MainClass.Settings.Resolution.Name);
                            if(cd != null){
                                cd.Value = resolution;
                                dvc.Conditions =condList.ToArray();
                            }

                        }
                    }
                }

                List<string> filesForPublish = new List<string>();

                foreach(string file in filesList){
                    //if (System.IO.Path.GetExtension(file)==".msc") continue;
                    if (System.IO.Path.GetExtension(file)==".ms") continue;

                    string checkFile =file;

                    if (System.IO.Path.GetExtension(file)==".msc")
                        checkFile = System.IO.Path.ChangeExtension(file,".ms");

                    string fileUpdate = FileUtility.AbsoluteToRelativePath(MainClass.Workspace.RootDirectory ,checkFile);

                    if ( project.FilesProperty != null){

                        // vyhldam property suborov a pozriem ci nemam nejake conditiony nastavene
                        FileItem fi =  project.FilesProperty.Find(x => x.SystemFilePath == fileUpdate);
                        if (fi != null)
                        {
                            if (fi.IsExcluded) continue;
                            if(fi.ConditionValues == null)continue;
                            foreach(CombineCondition cr in ccc.combineRule){

                                ConditionRule conRile = fi.ConditionValues.Find(x=>x.ConditionId == cr.ConditionId);
                                if (conRile != null){
                                    //if ((conRile.RuleId != cr.RuleId)) // subor ma condition daneho typu, ale nastavenu na inu hodnotu
                                    //goto nav;

                                    int resolutionId = -1;

                                    if(conRile.ConditionId == MainClass.Settings.Resolution.Id){
                                        resolutionId=mergeResolutions.FindIndex(x=>x == conRile.RuleId);
                                        //continue;
                                    }

                                    // mam merge resolution a subor patri do niektoreho mergnuteho resolution
                                    if((conRile.ConditionId == MainClass.Settings.Resolution.Id) && (resolutionId>-1)){
                                        goto nav1;
                                    }

                                    // subor ma condition daneho typu, ale nastavenu na inu hodnotu
                                    if ((conRile.RuleId != cr.RuleId)){
                                        goto nav;
                                    }
                                }
                            }
                        }
                    }
                    nav1:
                    fileUpdate = FileUtility.AbsoluteToRelativePath(project.AbsolutProjectDir,file);
                    fileUpdate = FileUtility.TrimStartingDotCharacter(fileUpdate);
                    fileUpdate = FileUtility.TrimStartingDirectorySeparator(fileUpdate);
                    filesForPublish.Add(fileUpdate);

                    nav:;
                }

                dvc.Includes.Files = filesForPublish.ToArray();
                dvc.Output_Name = fileName;

                dvc.PublishPropertisFull = new List<PublishProperty>();
                foreach(PublishProperty pp in dvc.PublishPropertisMask){
                    PublishProperty ppFull = new PublishProperty(pp.PublishName);
                    ppFull.PublishValue = project.ConvertProjectMaskPathToFull(pp.PublishValue);

                    dvc.PublishPropertisFull.Add(ppFull);
                }

                /*if(dvc.Includes.Skin != null){
                    dvc.Includes.Skin.ResolutionJson = dvc.Includes.Skin.Resolution;
                    if(!String.IsNullOrEmpty(dvc.Includes.Skin.Name)){
                        if(project.IncludeAllResolution){
                            dvc.Includes.Skin.ResolutionJson = "*";
                        }
                    }
                }*/

                //dvc.Includes.Files
                dvc.LogDebug = MainClass.Settings.LogPublish;
                dvc.ApplicationType = project.ApplicationType;
                dvc.FacebookAppID = project.FacebookAppID;
                if(String.IsNullOrEmpty(project.FacebookAppID))
                    dvc.FacebookAppID ="";

                string path = System.IO.Path.Combine(dirPublish,"settings.mso");//fileName+".mso"); //dvc.TargetPlatform + "_settings.mso");
                string json = dvc.GenerateJson();//GenerateJson(dvc);

                if(String.IsNullOrEmpty(json)){
                    SetError(MainClass.Languages.Translate("cannot_generate_mso"),parentTask);
                    continue;
                }

                try {
                    using (StreamWriter file = new StreamWriter(path)) {
                        file.Write(json);
                        file.Close();
                    }

                } catch {
                    SetError(MainClass.Languages.Translate("cannot_generate_mso"), parentTask);
                    //isPublishError = true;
                    continue;
                }

                //var platformRule = MainClass.Settings.Platform.Rules.Find(x => x.Id == dvc.TargetPlatformId);

                string appFile =dvc.Platform.Specific+ ".app"; /*dvc.TargetPlatform*///platformRule.Specific + ".app";
                string fullAppPath = System.IO.Path.Combine(MainClass.Settings.PublishDirectory,appFile);

                if (!System.IO.File.Exists(fullAppPath) ){
                    SetError(MainClass.Languages.Translate("publish_tool_not_found_f2"), parentTask);
                    continue;
                }

                RunPublishTool(appFile,parentTask);

                if(MainClass.Platform.IsMac){
                    ExitPublish(null,null);
                }

                if(devicePublishError){
                    allPublishError = true;
                    parentTask.Message =MainClass.Languages.Translate("publish_error");
                    //Console.WriteLine(parentTask.Child.Message);
                    output.Add(parentTask);
                    stateTask = StateEnum.ERROR;
                }
                else{
                    parentTask.Message = MainClass.Languages.Translate("publish_successfully_done");
                    output.Add(parentTask);
                }

                /*if (RunPublishTool(appFile,parentTask) ){
                    parentTask.Message =MainClass.Languages.Translate("publish_successfully_done");
                    output.Add(parentTask);

                    //output.Add(new TaskMessage(MainClass.Languages.Translate("publish_successfully_done"),dvc.Platform.Specific,null));
                } else {
                    parentTask.Message =MainClass.Languages.Translate("publish_error");
                    Console.WriteLine(parentTask.Child.Message);
                    output.Add(parentTask);
                    stateTask = StateEnum.ERROR;
                    isPublishError = true;
                    //output.Add(new TaskMessage(MainClass.Languages.Translate("publish_error"),dvc.Platform.Specific,null));
                }*/

                MainClass.MainWindow.ProgressStep();
                if (progressDialog != null)
                    cancelled = progressDialog.Update (fileName );
            }

            MainClass.MainWindow.ProgressEnd();

            if (progressDialog != null){
                progressDialog.Destroy();
            }

            RestoreBackup(hashAppPath,bakAppPath);

            if(allPublishError){
                this.stateTask = StateEnum.ERROR;
                string s = allErrors.ToString();
                if(s.Length > 120){
                    s = s.Substring(0,120);
                    s= s+ " ... and more.";
                }

                ShowError(MainClass.Languages.Translate("publish_error"), s);
                return false;
            } else {
                this.stateTask = StateEnum.OK;
                ShowInfo(MainClass.Languages.Translate("publish_successfully_done"), "");

                if(MainClass.Settings.OpenOutputAfterPublish){
                    if (!String.IsNullOrEmpty(project.ProjectOutput)){
                        MainClass.Tools.OpenFolder(project.OutputMaskToFullPath);
                    }
                }

                return true;
            }

            /*if(this.stateTask == StateEnum.ERROR){

                string s = allErrors.ToString();
                if(s.Length > 120){
                    s = s.Substring(0,120);
                    s= s+ " ... and more.";
                }

                ShowError(MainClass.Languages.Translate("publish_error"), s);
                return false;
            } else {
                ShowInfo(MainClass.Languages.Translate("publish_successfully_done"), "");

                if(MainClass.Settings.OpenOutputAfterPublish){
                    if (!String.IsNullOrEmpty(project.ProjectOutput)){
                        MainClass.Tools.OpenFolder(project.OutputMaskToFullPath);
                    }
                }

                return true;
            }*/
        }
示例#2
0
文件: Project.cs 项目: moscrif/ide
        public bool Export(string outputFile, bool Archive)
        {
            /*if (System.IO.File.Exists(outputFile)){

                MessageDialogs md =
                    new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, MainClass.Languages.Translate("file_notcreate_is_exist") ,outputFile, Gtk.MessageType.Error);
                 return false;
            }*/

            string[] filePaths = Directory.GetFiles(AbsolutProjectDir, "*",SearchOption.AllDirectories);
            List<string> fonts = new List<string>();

            int lng = filePaths.Length;

            int folderOffset = MainClass.Workspace.RootDirectory.Length;//compressDir.Length + (compressDir.EndsWith("\\") ? 0 : 1);
            string signingOld = String.Empty;
            Device device = this.DevicesSettings.Find(x=>x.Devicetype == DeviceType.iOS_5_0);
            if(device!= null){
                PublishProperty ppSigning = device.PublishPropertisMask.Find(x=>x.PublishName== KEY_CODESIGNINGIDENTITY);
                if(ppSigning!= null){
                    signingOld = ppSigning.PublishValue;
                    ppSigning.PublishValue = "";
                    try{
                        Save();
                    } catch (Exception ex){
                        Tool.Logger.Error(ex.Message);
                    }
                }
            }

            if(Archive){
                foreach (string lib in this.AppFile.Libs){
                    string libPath = System.IO.Path.Combine(MainClass.Workspace.RootDirectory,lib);

                    if(Directory.Exists(libPath)){
                        try{
                            filePaths = Directory.GetFiles(libPath, "*",SearchOption.AllDirectories);
                            lng = lng  + filePaths.Length;
                        }catch(Exception ex) {
                            Tool.Logger.Error(ex.Message);
                        }
                    }
                }

                filePaths = Directory.GetFiles(MainClass.Workspace.RootDirectory, "*.ttf",SearchOption.TopDirectoryOnly);

                if(MainClass.Platform.IsMac){// for Mac UpperCase
                    string[]  filePaths2 = Directory.GetFiles(MainClass.Workspace.RootDirectory, "*.TTF",SearchOption.TopDirectoryOnly);

                    var list = new List<string>();
                    list.AddRange(filePaths);
                    list.AddRange(filePaths2);
                    filePaths = list.ToArray();

                }

                foreach (Device d in this.DevicesSettings){
                    foreach (string font in d.Includes.Fonts){

                        string fontPath = System.IO.Path.Combine(MainClass.Workspace.RootDirectory ,font);
                        if( System.IO.File.Exists(fontPath) && fonts.FindIndex(x=>x == fontPath)<0 ){

                            System.IO.FileInfo fi = new FileInfo(fontPath);
                            if(fi.DirectoryName == MainClass.Workspace.RootDirectory) // only font from workspace
                                fonts.Add(fontPath);
                        }
                    }
                }
                lng = lng +fonts.Count;
            }

            progressDialog = new ProgressDialog("Compressed...",ProgressDialog.CancelButtonType.None,lng+2,MainClass.MainWindow);

            /*Timer timer = new Timer();
            timer.Interval = 240;
            timer.Elapsed += new ElapsedEventHandler(OnTimeElapsed);
            timer.Start();*/

            FileStream fsOut = File.Create(outputFile);
            ZipOutputStream zipStream = new ZipOutputStream(fsOut);
            zipStream.SetLevel(4);

            string[] files = new string[] {this.AbsolutAppFilePath,this.FilePath};

            foreach (string file in files){
                FileInfo fi = new FileInfo(file);

                string entryName = System.IO.Path.GetFileName(file); //file.Substring(folderOffset);
                entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
                ZipEntry newEntry = new ZipEntry(entryName);
                newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity

                // Specifying the AESKeySize triggers AES encryption. Allowable values are 0 (off), 128 or 256.
                //   newEntry.AESKeySize = 256;

                // To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
                // you need to do one of the following: Specify UseZip64.Off, or set the Size.
                // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
                // but the zip will be in Zip64 format which not all utilities can understand.
                //   zipStream.UseZip64 = UseZip64.Off;
                newEntry.Size = fi.Length;

                zipStream.PutNextEntry(newEntry);

                // Zip the file in buffered chunks
                // the "using" will close the stream even if an exception occurs
                progressDialog.Update(entryName);
                byte[ ] buffer = new byte[4096];
                using (FileStream streamReader = File.OpenRead(file)) {
                    ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(streamReader, zipStream, buffer);
                }
                zipStream.CloseEntry();
            }

            foreach (string file in fonts){
                FileInfo fi = new FileInfo(file);

                string entryName = System.IO.Path.GetFileName(file); //file.Substring(folderOffset);
                entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
                ZipEntry newEntry = new ZipEntry(entryName);
                newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity

                // Specifying the AESKeySize triggers AES encryption. Allowable values are 0 (off), 128 or 256.
                //   newEntry.AESKeySize = 256;

                // To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
                // you need to do one of the following: Specify UseZip64.Off, or set the Size.
                // If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
                // but the zip will be in Zip64 format which not all utilities can understand.
                //   zipStream.UseZip64 = UseZip64.Off;
                newEntry.Size = fi.Length;

                zipStream.PutNextEntry(newEntry);

                // Zip the file in buffered chunks
                // the "using" will close the stream even if an exception occurs
                progressDialog.Update(entryName);
                byte[ ] buffer = new byte[4096];
                using (FileStream streamReader = File.OpenRead(file)) {
                    ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(streamReader, zipStream, buffer);
                }
                zipStream.CloseEntry();
            }

            CompressFolder(this.AbsolutProjectDir, zipStream, folderOffset);

            if(Archive){
                foreach (string lib in this.AppFile.Libs){
                    string libPath = System.IO.Path.Combine(MainClass.Workspace.RootDirectory,lib);
                    if(System.IO.Directory.Exists(libPath)){
                        CompressFolder(libPath, zipStream, folderOffset);
                    }
                }
            }

            if(!String.IsNullOrEmpty(signingOld)){
                device = this.DevicesSettings.Find(x=>x.Devicetype == DeviceType.iOS_5_0);
                if(device!= null){
                    PublishProperty ppSigning = device.PublishPropertisMask.Find(x=>x.PublishName== KEY_CODESIGNINGIDENTITY);
                    if(ppSigning!= null){
                        ppSigning.PublishValue = signingOld;
                        try{
                            Save();
                        } catch (Exception ex){
                            Tool.Logger.Error(ex.Message);
                        }
                    }
                }
            }

            zipStream.IsStreamOwner = true;
            zipStream.Close();
            progressDialog.Destroy();
            return true;
        }
示例#3
0
        protected override void OnActivated()
        {
            MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.OkCancel, "Are you sure?", "", Gtk.MessageType.Question);
            int result = md.ShowDialog();
            if(result != (int)Gtk.ResponseType.Ok){
                return;
            }

            ProgressDialog progressDialog;

            string filename = System.IO.Path.Combine(MainClass.Paths.ConfingDir, "completedcache");
            sqlLiteDal = new SqlLiteDal(filename);

            string sql = "";

            if(sqlLiteDal.CheckExistTable("completed") ){
                sql = "DROP TABLE completed ;";
                sqlLiteDal.RunSqlScalar(sql);
            }

            sql = "CREATE TABLE completed (id INTEGER PRIMARY KEY, name TEXT, signature TEXT, type NUMERIC, parent TEXT,summary TEXT ,returnType TEXT ) ;";
            sqlLiteDal.RunSqlScalar(sql);

            SyntaxMode mode = new SyntaxMode();
            mode = SyntaxModeService.GetSyntaxMode("text/moscrif");

            progressDialog = new ProgressDialog("Generated...",ProgressDialog.CancelButtonType.None, mode.Keywords.Count() ,MainClass.MainWindow);

            foreach (Keywords kw in mode.Keywords){

                progressDialog.Update(kw.ToString());
                foreach (string wrd in kw.Words){
                        insertNewRow(wrd,wrd,(int)CompletionDataTyp.keywords,"","","");
                    }
            }

            Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog("data.json", null, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
            fc.TransientFor = MainClass.MainWindow;
            fc.SetCurrentFolder(@"d:\Work\docs-api\output\");

            if (fc.Run() != (int)ResponseType.Accept) {
                return;
            }
            string json ;
            string fileName = fc.Filename;
            progressDialog.Destroy();
            fc.Destroy();
            progressDialog = new ProgressDialog("Generated...",ProgressDialog.CancelButtonType.None,100 ,MainClass.MainWindow);

            using (StreamReader file = new StreamReader(fileName)) {
                json = file.ReadToEnd();
                file.Close();
                file.Dispose();
            }

            //XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json);
            //doc.Save(fileName+"xml");

            /*JObject jDoc= JObject.Parse(json);
            //classes
            Console.WriteLine("o.Count->"+jDoc.Count);

            foreach (JProperty jp in jDoc.Properties()){
                Console.WriteLine(jp.Name);
            }
            Console.WriteLine("------------");
            JObject classes = (JObject)jDoc["classes"];
            foreach (JProperty jp in classes.Properties()){
                Console.WriteLine(jp.Name);
                JObject classDefin = (JObject)classes[jp.Name];
                string name = (string)classDefin["name"];
                string shortname = (string)classDefin["shortname"];
                string description = (string)classDefin["description"];
                //string type = (string)classDefin["type"];
                insertNewRow(name,name,(int)CompletionDataTyp.types,"",description,name);
            }
            Console.WriteLine("------------");

            JArray classitems = (JArray)jDoc["classitems"];
            foreach (JObject classitem in classitems){

                string name = (string)classitem["name"];
                Console.WriteLine(name);

                string description = (string)classitem["description"];
                string itemtype = (string)classitem["itemtype"];
                string classParent = (string)classitem["class"];
                string signature = (string)classitem["name"];
                CompletionDataTyp type = CompletionDataTyp.noting;
                string returnType= classParent;

                switch (itemtype){
                    case "method":{
                        JArray paramsArray = (JArray)classitem["params"];
                        signature = signature+ GetParams(paramsArray);
                        type = CompletionDataTyp.members;
                        JObject returnJO =(JObject)classitem["return"] ;
                        if(returnJO!=null){
                            returnType = (string)returnJO["type"];
                        }

                        break;
                    }
                    case "property":{

                        string tmpType = (string)classitem["type"];
                        if(!String.IsNullOrEmpty(tmpType)){
                            returnType=tmpType.Replace("{","").Replace("}","");
                        }
                        type = CompletionDataTyp.properties;
                        break;
                    }
                    case "event":{
                        JArray paramsArray = (JArray)classitem["params"];
                        signature = signature+ GetParams(paramsArray);
                        type = CompletionDataTyp.events;
                        break;
                    }
                    case "attribute":{
                        continue;
                        break;
                    }
                    default:{
                        type = CompletionDataTyp.noting;
                        break;
                    }

                }

                insertNewRow(name,signature,(int)type,classParent,description,returnType);
            }*/
            //classitems

            //			string name = (string)o["project"]["name"];
            //			Console.WriteLine(name);

            progressDialog.Destroy();

            md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "Done", "", Gtk.MessageType.Info);
            md.ShowDialog();

            return;
            /*

            Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog("Select DOC Directory (with xml)", null, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
            FileInfo[] xmls = new FileInfo[]{};

            if (fc.Run() == (int)ResponseType.Accept) {

                DirectoryInfo di = new DirectoryInfo(fc.Filename);
                xmls = di.GetFiles("*.xml");
                //List<string> output = new List<string>();

                //MainClass.CompletedCache.ListTypes= listSignature.Distinct().ToList();
                //MainClass.CompletedCache.ListMembers= listMemberSignature.Distinct().ToList();
            }
            progressDialog.Destroy();
            fc.Destroy();
            progressDialog = new ProgressDialog("Generated...",ProgressDialog.CancelButtonType.None,xmls.Length ,MainClass.MainWindow);
                    foreach (FileInfo xml in xmls)
                    {
                        try
                        {
                    progressDialog.Update(xml.Name);
                    if(!xml.Name.StartsWith("_"))
                        getObject(xml.FullName);
                        }
                        catch(Exception ex) {
                            Console.WriteLine(ex.Message);
                            Console.WriteLine(ex.StackTrace);
                            return;
                        }
                    }
            progressDialog.Destroy();

            md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "Done", "", Gtk.MessageType.Info);
            md.ShowDialog();*/
        }