Example #1
0
        public bool ExecuteTask()
        {
            stateTask = StateEnum.OK;

            if (MainClass.MainWindow.RunningEmulator) {
            output.Add(new TaskMessage(MainClass.Languages.Translate("emulator_is_running")));
            Tool.Logger.Error(MainClass.Languages.Translate("emulator_is_running"),null);
            stateTask = StateEnum.ERROR;
            return false;
            }

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

            string file = System.IO.Path.Combine(MainClass.Settings.EmulatorDirectory,  "Moscrif.app");//.app

            if(!System.IO.Directory.Exists(file) ){
                output.Add(new TaskMessage(MainClass.Languages.Translate("emulator_not_found")));
                stateTask = StateEnum.ERROR;
                Tool.Logger.Error(MainClass.Languages.Translate("emulator_not_found"),null);
                return false;
            }

            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 MAC ->{0}",cmd),null);
            if(!System.IO.File.Exists(file) ){
                output.Add(new TaskMessage(MainClass.Languages.Translate("emulator_not_found")));
                stateTask = StateEnum.ERROR;
                Tool.Logger.Error(MainClass.Languages.Translate("emulator_not_found"),null);
                return false;
            }

            } else {
            Tool.Logger.LogDebugInfo(String.Format("command WIN ->{0}",cmd),null);
            if (!System.IO.File.Exists(cmd)) {
                output.Add(new TaskMessage(MainClass.Languages.Translate("emulator_not_found")));
                stateTask = StateEnum.ERROR;
                return false;
            }
            }

            if (MainClass.Workspace.ActualProject == null) {
                output.Add(new TaskMessage(MainClass.Languages.Translate("emulator_not_found")));
                stateTask = StateEnum.ERROR;
                return false;
            }
            project = MainClass.Workspace.ActualProject;
            try {
                List<string> list = new List<string>();
                GetComands(project.AbsolutProjectDir, ref list);

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

                foreach (string f in list) {

                    if (exitCompile) {
                        MainClass.MainWindow.ProgressEnd();
                        return false;
                    }

                    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);
                    }

                    string a = args;
                    ProcessService ps = new ProcessService();
                    ProcessWrapper pw = ps.StartProcess(cmd, a, fdir, ProcessOutputChange, ProcessOutputChange);

                    MainClass.MainWindow.ProgressStep();

                    //pw.WaitForOutput();
                    pw.Exited += delegate(object sender, EventArgs e) {
                        //Console.WriteLine("pw.Exited");
                        ParseOutput("Exit Compilation",pw.StartInfo.WorkingDirectory);
                    };
                    //return true;
                }
                //output.Add(file);

            } catch (Exception ex) {
                output.Add(new TaskMessage(">>" + ex.Message));
                stateTask = StateEnum.ERROR;
                return false;
            } finally {
                MainClass.MainWindow.ProgressEnd();
            }
            //Console.WriteLine("0 >>"+stateTask);
            return true;
        }
Example #2
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;
            }*/
        }
Example #3
0
        public bool ExecuteTask()
        {
            stateTask = StateEnum.OK;
            string tmpFile = System.IO.Path.Combine(MainClass.Paths.TempPrecompileDir, "temp.ms");

            try {
                using (StreamWriter file = new StreamWriter(tmpFile)) {
                    file.Write(pd.Text);
                    file.Close();
                    file.Dispose();
            }
            } catch {

            }

            if(MainClass.MainWindow.RunningEmulator){
                output.Add( new TaskMessage(MainClass.Languages.Translate("emulator_is_running")));
                stateTask = StateEnum.ERROR;
                return false;
            }

            string cmd = Path.Combine(MainClass.Paths.TempPrecompileDir,  "moscrif.exe");

            if (MainClass.Platform.IsMac) {

                string file = System.IO.Path.Combine(MainClass.Paths.TempPrecompileDir,  "Moscrif.app");//.app

                if(!System.IO.Directory.Exists(file) ){
                    output.Add(new TaskMessage(MainClass.Languages.Translate("emulator_not_found")));
                    stateTask = StateEnum.ERROR;
                    Tool.Logger.Error(MainClass.Languages.Translate("emulator_not_found"),null);
                    return false;
                }

                file = System.IO.Path.Combine(file,  "Contents");
                file = System.IO.Path.Combine(file,  "MacOS");
                file = System.IO.Path.Combine(file,  "Moscrif");
                cmd = file;

                if(!System.IO.File.Exists(file) ){
                    output.Add(new TaskMessage(MainClass.Languages.Translate("emulator_not_found")));
                    stateTask = StateEnum.ERROR;
                    Tool.Logger.Error(MainClass.Languages.Translate("emulator_not_found"),null);
                    return false;
                }

            } else {
                if (!System.IO.File.Exists(cmd)) {
                    output.Add(new TaskMessage(MainClass.Languages.Translate("emulator_not_found")));
                    stateTask = StateEnum.ERROR;
                    return false;
                }
            }

            if(!System.IO.File.Exists(tmpFile)  ){
                output.Add( new TaskMessage(MainClass.Languages.Translate("file_not_exist_f1", tmpFile)));
                stateTask = StateEnum.ERROR;
                return false;
            }

            //AppFile appFile = MainClass.Workspace.ActualProject.AppFile;
            //string args = String.Format("/d \"{0}\" /c {1} /o console", MainClass.Tools.TempDir, "temp.ms");

            //string args = String.Format("/c {0} /o console /d \"{1}\" ", "temp.ms",MainClass.Tools.TempDir);
            string args = String.Format(" /d \"{0}\" /c {1} /o console ", MainClass.Paths.TempPrecompileDir,"temp.ms");

            if(MainClass.Platform.IsMac){
                args = String.Format(" -d \"{0}\" -c {1} -o console ", MainClass.Paths.TempPrecompileDir,"temp.ms");
            }

            try{

                //MainClass.MainWindow.RunProcess(cmd, args, MainClass.Settings.EmulatorDirectory);

                //MainClass.MainWindow.RunProcess("cmd.exe", "/c dir *.*", MainClass.Tools.TempDir);
                //ProcessWrapper pw = MainClass.ProcessService.StartProcess("cmd.exe", "/c dir *.*", MainClass.Tools.TempDir,ProcessOutputChange, ProcessErrorChange);

                ProcessService ps = new ProcessService();
                ProcessWrapper pw = ps.StartProcess(cmd,
                 args,
                //"D:\\Work\\moscrift.Ide\\bin\\Debug\\Workspace4\\x000001"
                               MainClass.Paths.TempPrecompileDir
                // MainClass.Settings.EmulatorDirectory
                //                                     ""
                , ProcessOutputChange,ProcessOutputChange);// ProcessErrorChange);
                pw.Exited += delegate(object sender, EventArgs e) {
                    //Console.WriteLine("pw.Exited");
                    //ParseOutput("Exit Compilation");
                };
                pw.WaitForOutput(1000);
                //pw.WaitForOutput(1000);
                //output.Add(file);

            }catch (Exception ex){

                output.Add( new TaskMessage(ex.Message));
                stateTask = StateEnum.ERROR;
                return false;
            }
            finally{
                //ps.Dispose();
            }
                //Console.WriteLine("0 >>"+stateTask);
                return true;
        }