/// <summary>
        /// Desactivate an active profile. If cannot complete the operation, does nothing and return an error code.
        /// </summary>
        /// <returns></returns>
        public int desactivateActiveProfile(string profileName, out string outMsg)
        {
            log.Debug("## manager.desactivateActiveProfile() ##########################################");
            log.Debug("# desactivateActiveProfile() profileName:" + profileName);
            int    ret            = Errors.SUCCESS;
            string id             = "";
            string name           = "";
            string color          = "";
            string errMsg         = "";
            bool   retVal         = false;
            bool   opWasCancelled = false;

            // check state
            this.updateManagerState();
            if ((this.applicationState != SPMState.ACTIVE_AND_DESACTIVATED_PROFILES) &&
                (this.applicationState != SPMState.ACTIVE_ONLY))
            {
                outMsg = "Invalid state for desactivateActiveProfile operation! State:" + this.applicationState;
                log.Error(" ** " + outMsg);
                log.Error(" ** Errors.ERR_INVALID_STATE_FOR_REQUESTED_OPERATION_2");
                return(Errors.ERR_INVALID_STATE_FOR_REQUESTED_OPERATION_2);
            }

            // check if integrity file information matches
            profileName.Trim();
            if (!this.integrityFile.activeIntegrityFileExists())
            {
                outMsg = "INTEGRITY FILE FOR PROFILE " + profileName + " DOES NOT EXIST. CANNOT COMPLETE ACTION.";
                log.Error(" ** " + outMsg);
                log.Error(" **  Errors.ERR_FILE_NOT_EXIST");
                return(Errors.ERR_FILE_NOT_EXIST);
            }
            List <string> intItem = this.integrityFile.activeIntegrityFileItems();

            if (intItem.Count < Consts.INTEGRITY_FILE_ITEMS)
            {
                outMsg = "INTEGRITY FILE FOR PROFILE " + profileName + " IS NOT ON THE RIGHT FORMAT.";
                log.Error(" ** " + outMsg);
                log.Error(" ** Errors.ERR_ACTIVE_PROFILE_CORRUPTED_1");
                return(Errors.ERR_ACTIVE_PROFILE_CORRUPTED_1);
            }
            if (intItem[0].Trim() != profileName)
            {
                outMsg = "Active profile corrupted. Error parsing integrity file.";
                log.Warn(" ** " + outMsg);
                retVal = this.integrityFile.deleteActiveIntegrityFile(out errMsg);
                if (!retVal)
                {
                    log.Error(" ** ERROR @ this.integrityFile.deleteActiveIntegrityFile(). Could not delete integrity file. Message: " + errMsg);
                }
                this.updateManagerState();
                log.Error(" ** Errors.ERR_ACTIVE_PROFILE_CORRUPTED_2");
                return(Errors.ERR_ACTIVE_PROFILE_CORRUPTED_2);
            }
            log.Debug(" -- integrity file OK! " + id + ", " + name + ", " + color);

            // create backup dir if does not exit
            ret = this.createBackupProfilesFolder(profileName, out errMsg);
            if (ret != Errors.SUCCESS)
            {
                outMsg = "Could not create backup profile Folder: " + errMsg;
                log.Error(" ** " + outMsg);
                return(ret);
            }
            log.Debug(" -- createBackupProfilesFolder OK!");
            // check instalation before moving
            string errPath  = "";
            string errLabel = "";

            ret = this.paths.checkInstallationPaths(out errPath, out errLabel);
            if (ret != Errors.SUCCESS)
            {
                outMsg = "Installation Path " + errLabel + ": <" + errPath + ">";
                return(ret);
            }
            ListPaths listPathsDst = this.paths.getAllPaths_BkpProf(profileName);
            ListPaths listPathsSrc = this.paths.getAllPaths_AppGame();
            // check consinstency
            string errLabel1 = "";
            string errLabel2 = "";

            if (!listPathsSrc.checkLabels(listPathsDst, out errLabel1, out errLabel2))
            {
                outMsg = "sourceType: " + errLabel1 + ", destination:" + errLabel2;
                log.Error(" ** Source and destination folder are mislabeled!!");
                log.Error(" ** errLabel1:" + errLabel1);
                log.Error(" ** errLabel2:" + errLabel2);
                log.Error(" ** outErrMsg:" + outMsg);
                log.Error(" ** Source Paths:" + CSharp.listToCsv(listPathsSrc.listPaths));
                log.Error(" ** Destination Paths:" + CSharp.listToCsv(listPathsDst.listPaths));
                log.Error(" ** Errors.ERR_SOURCE_DESTINATION_DONT_MATCH_DESACTIVATEACTIVE");
                return(Errors.ERR_SOURCE_DESTINATION_DONT_MATCH_DESACTIVATEACTIVE);
            }
            string[] destinationDirs = listPathsDst.vecPaths;
            string[] sourceDirs      = listPathsSrc.vecPaths;
            string   errSrcDir       = "";
            string   errDstDir       = "";
            bool     sucess          = CSharp.stackMv(sourceDirs, destinationDirs, true, LogMethod.LOGGER,
                                                      out errMsg, out errSrcDir, out errDstDir, out opWasCancelled);

            if (!sucess)
            {
                if (opWasCancelled)
                {
                    outMsg = "Operation cancelled by the User";
                    log.Warn(" ** outMsg: " + outMsg);
                    log.Warn(" ** errMsg: " + errMsg);
                    log.Warn(" ** errSrcDir:" + errSrcDir);
                    log.Warn(" ** errDstDir: " + errDstDir);
                    log.Warn(" ** Errors.INFO_OPERATION_CANCELLED_BY_USER");
                    return(Errors.INFO_OPERATION_CANCELLED_BY_USER);
                }
                outMsg = errMsg + " errSrcDir:<" + errSrcDir + ">" + ", errDstDir:<" + errDstDir + ">";
                log.Error(" ** outMsg: " + outMsg);
                log.Error(" ** errMsg: " + errMsg);
                log.Error(" ** errSrcDir:" + errSrcDir);
                log.Error(" ** errDstDir: " + errDstDir);
                log.Error(" ** Errors.ERR_MOVING_DIRECTORIES_2");
                return(Errors.ERR_MOVING_DIRECTORIES_2);
            }
            this.reloadState();
            outMsg = "";
            return(Errors.SUCCESS);
        }
        /// <summary>
        /// If there is no profile installed, set a desactivated profile as active. Otherwise does nothing
        /// and returns an error code.
        /// </summary>
        /// <param name="profileName">Alpanumeric string</param>
        /// <returns></returns>
        public int activateDesactivatedProfile(string profileName, out string outErrMsg)
        {
            bool opWasCancelled = false;

            log.Debug("## manager.activateDesactivatedProfile() #######################################");
            log.Debug("# activateDesactivatedProfile() profileName:" + profileName);
            log.Debug("STEP 1: Check Settings...");
            this.updateManagerState();
            if (this.applicationState != SPMState.DESACTIVATED_ONLY)
            {
                outErrMsg = "Invalid state for requested operation. This operation may only be completed if the aplication state is SPMState.DESACTIVATED_ONLY.";
                log.Warn(" -- " + outErrMsg);
                log.Error(" ** Errors.ERR_INVALID_STATE_FOR_REQUESTED_OPERATION_5");
                return(Errors.ERR_INVALID_STATE_FOR_REQUESTED_OPERATION_5);
            }
            profileName = profileName.Trim();
            if (profileName == null || profileName.Equals(""))
            {
                outErrMsg = "profile name is empty";
                log.Warn(" -- " + outErrMsg);
                log.Warn(" -- Errors.ERR_INVALID_PROFILE_NAME_1");
                return(Errors.ERR_INVALID_PROFILE_NAME_1);
            }

            log.Debug("STEP 2: search profile to activate...");
            SPProfile profToActivate = null;

            foreach (var item in this.listDesactivated)
            {
                if (item.name.Trim() == profileName.Trim())
                {
                    profToActivate = item;
                    break;
                }
            }
            if (profToActivate == null)
            {
                outErrMsg = "Specified profile could not be found, ERR_INVALID_PROFILE_NAME";
                log.Warn(" -- " + outErrMsg);
                log.Error(" ** Errors.ERR_INVALID_PROFILE_NAME_2");
                return(Errors.ERR_INVALID_PROFILE_NAME_2);
            }

            log.Debug("STEP 3: moving folders from backup to root dir...");
            // check backup before moving
            string errPathOut = "";
            string errLabel   = "";
            int    ret        = this.paths.checkBackupInstallationPaths(profileName, out errPathOut, out errLabel);

            if (ret != Errors.SUCCESS)
            {
                outErrMsg = "Backup Path (" + profileName + ") " + errLabel + ": <" + errPathOut + ">";
                return(ret);
            }
            // load all paths
            ListPaths listPathsDst = this.paths.getAllPaths_App();
            ListPaths listPathsSrc = this.paths.getAllPaths_BkpProfGame(profileName);
            string    errLabel1    = "";
            string    errLabel2    = "";

            if (!listPathsSrc.checkLabels(listPathsDst, out errLabel1, out errLabel2))
            {
                outErrMsg = "sourceType: " + errLabel1 + ", destination:" + errLabel2;
                log.Error(" ** Source and destination folder are mislabeled!!");
                log.Error(" ** errLabel1:" + errLabel1);
                log.Error(" ** errLabel2:" + errLabel2);
                log.Error(" ** outErrMsg:" + outErrMsg);
                log.Error(" ** Source Paths:" + CSharp.listToCsv(listPathsSrc.listPaths));
                log.Error(" ** Destination Paths:" + CSharp.listToCsv(listPathsDst.listPaths));
                log.Error(" ** Errors.ERR_SOURCE_DESTINATION_DONT_MATCH_ACTIVATEDESACTIVATED");
                return(Errors.ERR_SOURCE_DESTINATION_DONT_MATCH_ACTIVATEDESACTIVATED);
            }
            string[] destinationDirs = listPathsDst.vecPaths;
            string[] sourceDirs      = listPathsSrc.vecPaths;
            string   errMsg          = "";
            string   errSrcDir       = "";
            string   errDstDir       = "";
            string   errPath         = "";
            bool     sucess          = CSharp.stackMv(sourceDirs, destinationDirs, true, LogMethod.LOGGER,
                                                      out errMsg, out errSrcDir, out errDstDir, out opWasCancelled);

            if (!sucess)
            {
                if (opWasCancelled)
                {
                    outErrMsg = "Operation cancelled by the User";
                    log.Warn(" ** outMsg: " + outErrMsg);
                    log.Warn(" ** errMsg: " + errMsg);
                    log.Warn(" ** errSrcDir:" + errSrcDir);
                    log.Warn(" ** errDstDir: " + errDstDir);
                    log.Warn(" ** Errors.ERR_MOVING_DIRECTORIES_2");
                    return(Errors.INFO_OPERATION_CANCELLED_BY_USER);
                }
                outErrMsg = "Error moving directories: SrcDir<" + errSrcDir + ">, DstDir<" + errDstDir + ">. Error Message:" + errMsg;
                log.Error(" ** " + outErrMsg);
                log.Error(" ** errMsg: " + errMsg);
                log.Error(" ** errSrcDir:" + errSrcDir);
                log.Error(" ** errDstDir: " + errDstDir);
                log.Error(" ** Errors.ERR_MOVING_DIRECTORIES_1");
                return(Errors.ERR_MOVING_DIRECTORIES_1);
            }

            log.Debug("STEP 4: create integrity file...");
            errMsg  = "";
            errPath = "";
            if (!this.integrityFile.updateActiveIntegrityFile(profToActivate, out errMsg, out errPath))
            {
                outErrMsg = "Could not create intregrity file. Message:" + errMsg + ". Error Path:" + errPath;
                log.Error(" ** outErrMsg:" + outErrMsg);
                log.Error(" ** ERROR errMsg:" + errMsg + ", errPath:" + errPath);
                log.Error(" ** Errors.ERR_CANNOT_CREATE_INTEGRITY_FILE_2");
                return(Errors.ERR_CANNOT_CREATE_INTEGRITY_FILE_2);
            }

            log.Debug("STEP 5: update manager state...");
            profToActivate.isReady = true;
            this.reloadState();

            outErrMsg = "";
            return(Errors.SUCCESS);
        }