Example #1
0
            public void RestoreSFAR(bool batchRestore, Action signalRestoreCompleted = null)
            {
                bool?restore = batchRestore;

                if (!restore.Value)
                {
                    restore = RestoreConfirmationCallback?.Invoke(FilePath);
                }
                if (restore.HasValue && restore.Value)
                {
                    NamedBackgroundWorker nbw = new NamedBackgroundWorker(@"RestoreSFARThread");
                    nbw.DoWork += (a, b) =>
                    {
                        var backupFile = Path.Combine(BackupService.GetGameBackupPath(target.Game), FilePath);
                        var targetFile = Path.Combine(target.TargetPath, FilePath);
                        Restoring = true;
                        Log.Information($@"Restoring SFAR from backup: {backupFile} {targetFile}");
                        XCopy.Copy(backupFile, targetFile, true, true,
                                   (o, pce) =>
                        {
                            RestoreButtonContent = M3L.GetString(M3L.string_interp_restoringXpercent,
                                                                 pce.ProgressPercentage.ToString());
                        });
                        var unpackedFiles = Directory.GetFiles(DLCDirectory, @"*", SearchOption.AllDirectories);
                        RestoreButtonContent = M3L.GetString(M3L.string_cleaningUp);
                        foreach (var file in unpackedFiles)
                        {
                            if (!file.EndsWith(@".sfar"))
                            {
                                Log.Information(@"Deleting unpacked file: " + file);
                                File.Delete(file);
                            }
                        }

                        Utilities.DeleteEmptySubdirectories(DLCDirectory);
                        RestoreButtonContent = M3L.GetString(M3L.string_restored);
                    };
                    nbw.RunWorkerCompleted += (a, b) =>
                    {
                        if (b.Error != null)
                        {
                            Log.Error($@"Exception occured in {nbw.Name} thread: {b.Error.Message}");
                        }
                        //File.Copy(backupFile, targetFile, true);
                        //if (!batchRestore)
                        //{
                        RevalidateIsModified();
                        //restoreCompletedCallback?.Invoke();
                        //}
                        Restoring = false;
                        signalRestoreCompleted?.Invoke();
                    };
                    startingRestoreCallback?.Invoke();
                    nbw.RunWorkerAsync();
                }
            }
Example #2
0
        /// <summary>
        /// Right Click Function For Data Grid View - a.k.a Context Menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            // Pop a Dialog box
            // Fetch the DestDirName

            string destDirName = DesDirPath.Text;

            // create directory using selectedTps.Name + selectedTps.Date
            // transfer associated Ats with selected Tps to destination directory

            pbStatus.Value = (100 / selectedTps.ATSList.Count);

            if (destDirName == string.Empty)
            {
                // Configure the message box to be displayed
                string           messageBoxText = "Missing Destination Directory";
                string           caption        = "Error";
                MessageBoxButton button         = MessageBoxButton.OK;
                MessageBoxImage  icon           = MessageBoxImage.Error;
                MessageBox.Show(messageBoxText, caption, button, icon);
                DesDirPath.Focus();
                pbStatus.Value = 0;
                return;
            }

            foreach (ATS ats in selectedTps.ATSList)
            {
                StringBuilder sourceDirLoc = new StringBuilder(_workingdir);
                sourceDirLoc.Append('\\');
                sourceDirLoc.Append(ats.Name);

                StringBuilder destDirLoc = new StringBuilder(destDirName);
                destDirLoc.Append('\\');
                destDirLoc.Append(ats.Name);

                pbStatus.Value += pbStatus.Value;
                try
                {
                    Task xcopytask = Task.Factory.StartNew(() =>
                    {
                        XCopy.DirectoryCopy(sourceDirLoc.ToString(), destDirLoc.ToString(), true);
                    });
                    xcopytask.Wait();
                }
                catch (AggregateException ex)
                {
                    // Configure the message box to be displayed
                    string           messageBoxText = ex.InnerException.Message;
                    string           caption        = "Error";
                    MessageBoxButton button         = MessageBoxButton.OK;
                    MessageBoxImage  icon           = MessageBoxImage.Error;
                    MessageBox.Show(messageBoxText, caption, button, icon);
                }
            }
        }
Example #3
0
        private async void CopyFilesToFolder(Func <TransmittMedia, string> fullNameGenerate)
        {
            var selectedFiles = Thumbnails.Where(i => i.IsSelected).ToList();

            if (selectedFiles.Count == 0 && Thumbnails.Count > 0 && Xceed.Wpf.Toolkit.MessageBox.Show(Owner, "Select all files?", "No selected files", MessageBoxButton.YesNo, Resources["ExistStyle"] as Style) == MessageBoxResult.Yes)
            {
                selectedFiles = Thumbnails.ToList();
            }
            progressBar.Maximum       = Math.Max(Thumbnails.Where(i => i.IsSelected).Count(), 1);
            busyIndicator.IsBusy      = true;
            busyIndicator.BusyContent = "Please wait..." + Environment.NewLine + String.Format("{0} copied from {1}", progressBar.Value, progressBar.Maximum);
            foreach (var item in selectedFiles)
            {
                var pathFolder = fullNameGenerate(item);
                if (!System.IO.Directory.Exists(pathFolder))
                {
                    System.IO.Directory.CreateDirectory(pathFolder);
                }
                var destenation = System.IO.Path.Combine(pathFolder, item.FileInfo.Name);
                var info        = new FileInfo(destenation);
                progressBarDetail.Value = 0;
                if (!info.Exists)
                {
                    await XCopy.CopyAsync(item.FileInfo.FullName, destenation, false, true, (o, progress) =>
                    {
                        progressBarDetail.Dispatcher.InvokeAsync(() => { progressBarDetail.Value = (progress as ProgressChangedEventArgs).ProgressPercentage; });
                    });
                }
                else
                {
                    var Text   = String.Format("File {0} already exist. Old size {1} KB new size {2} KB. Overwrite?", item.FileInfo.Name, item.FileInfo.Length.AsKB(), info.Length.AsKB());
                    var result = Xceed.Wpf.Toolkit.MessageBox.Show(Owner, Text, "File already exists", MessageBoxButton.YesNo, Resources["ExistStyle"] as Style);
                    if (result == MessageBoxResult.Yes)
                    {
                        await XCopy.CopyAsync(item.FileInfo.FullName, destenation, true, true, (o, progress) =>
                        {
                            progressBarDetail.Dispatcher.InvokeAsync(() => { progressBarDetail.Value = (progress as ProgressChangedEventArgs).ProgressPercentage; });
                        });
                    }
                }
                Thumbnails.Remove(item);
                progressBar.Value += 1;
                progressBarDetail.Dispatcher.Invoke(() => { progressBarDetail.Value = 0; });
                busyIndicator.BusyContent = "Please wait..." + Environment.NewLine + String.Format("{0} copied from {1}", progressBar.Value, progressBar.Maximum);
                busyIndicator.InvalidateArrange();
                busyIndicator.UpdateLayout();
                this.UpdateLayout();
            }
            busyIndicator.IsBusy    = false;
            progressBar.Value       = 0;
            progressBarDetail.Value = 0;
            GC.Collect();
        }
        void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            string[] files = e.Argument as string[];

            XCopy.Copy(files[0], files[1], true, true, (o, pce) =>
            {
                worker.ReportProgress(pce.ProgressPercentage, files[0]);
            });

            e.Result = files[1];
        }
Example #5
0
        private void CopyFile(string source, string dest)
        {
            var started = DateTime.Now;

            XCopy.Copy(source, dest, true,
                       true,
                       (prog, total) =>
            {
                if (IsCancelled)
                {
                    return;
                }
                ChangeProgressBarEstimate(prog, total, started, true);
            }, CancellationTokenSource.Token);
        }
Example #6
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            ShutdownMode = ShutdownMode.OnExplicitShutdown;

            var tempDir   = Path.GetTempPath();
            var targetDir = Assembly.GetExecutingAssembly().Location;

            Console.WriteLine(@"Running Resource Generator!");
            // <path> <folder> <IsOverwriten> [msbuild]
            ResourceGenerator.Program.Run(new [] { $"{tempDir}Resources", "Tiles", "0", "msbuild" });
            Console.WriteLine($@"Sucessfully generated tiles in '{tempDir}Resources\Generated'");

            Console.WriteLine($@"Copying Generated tiles from '{tempDir}Resources\Generated' to '{targetDir}Images\Tiles'");
            XCopy.Run($@"{tempDir}Resources\Generated", $@"{targetDir}Images\Tiles");

            Core.Initialize();
        }
Example #7
0
            public void RestoreSFAR(bool batchRestore)
            {
                bool?restore = batchRestore;

                if (!restore.Value)
                {
                    restore = RestoreConfirmationCallback?.Invoke(FilePath);
                }
                if (restore.HasValue && restore.Value)
                {
                    //Todo: Background thread this maybe?
                    NamedBackgroundWorker bw = new NamedBackgroundWorker("RestoreSFARThread");
                    bw.DoWork += (a, b) =>
                    {
                        var backupFile = Path.Combine(Utilities.GetGameBackupPath(target.Game), FilePath);
                        var targetFile = Path.Combine(target.TargetPath, FilePath);
                        Restoring = true;
                        Log.Information("Restoring SFAR from backup: " + backupFile + " => " + targetFile);
                        XCopy.Copy(backupFile, targetFile, true, true, (o, pce) => { RestoreButtonContent = $"Restoring {pce.ProgressPercentage}%"; });
                        var unpackedFiles = Directory.GetFiles(DLCDirectory, "*", SearchOption.AllDirectories);
                        RestoreButtonContent = $"Cleaning up";
                        foreach (var file in unpackedFiles)
                        {
                            if (!file.EndsWith(".sfar"))
                            {
                                Log.Information("Deleting unpacked file: " + file);
                                File.Delete(file);
                            }
                        }
                        Utilities.DeleteEmptySubdirectories(DLCDirectory);
                        RestoreButtonContent = "Restored";
                    };
                    bw.RunWorkerCompleted += (a, b) =>
                    {
                        //File.Copy(backupFile, targetFile, true);
                        //if (!batchRestore)
                        //{
                        RevalidateIsModified();
                        //restoreCompletedCallback?.Invoke();
                        //}
                        Restoring = false;
                    };
                    startingRestoreCallback?.Invoke();
                    bw.RunWorkerAsync();
                }
            }
Example #8
0
 private void CopyInternal(string source, string dest, bool overwrite, bool isLargeTransfer, EventHandler <ProgressChangedEventArgs> progressChangedHandler, EventHandler completedHandler, XCopy.ErrorHandler errorHandler)
 {
     try
     {
         XCopy.CopyFileFlags copyFileFlags = XCopy.CopyFileFlags.COPY_FILE_RESTARTABLE;
         if (!overwrite)
         {
             copyFileFlags |= XCopy.CopyFileFlags.COPY_FILE_FAIL_IF_EXISTS;
         }
         if (isLargeTransfer)
         {
             copyFileFlags |= XCopy.CopyFileFlags.COPY_FILE_NO_BUFFERING;
         }
         this.Source = source;
         this._dst   = dest;
         if (progressChangedHandler != null)
         {
             this.ProgressChanged = (EventHandler <ProgressChangedEventArgs>)Delegate.Combine(this.ProgressChanged, progressChangedHandler);
         }
         if (completedHandler != null)
         {
             this.Completed = (EventHandler)Delegate.Combine(this.Completed, completedHandler);
         }
         if (!XCopy.CopyFileEx(this.Source, this._dst, new XCopy.CopyProgressRoutine(this.CopyProgressHandler), IntPtr.Zero, ref this._isCancelled, copyFileFlags))
         {
             throw new Win32Exception(Marshal.GetLastWin32Error());
         }
     }
     catch (Exception ex)
     {
         if (progressChangedHandler != null)
         {
             this.ProgressChanged = (EventHandler <ProgressChangedEventArgs>)Delegate.Remove(this.ProgressChanged, progressChangedHandler);
         }
         if (completedHandler != null)
         {
             this.Completed = (EventHandler)Delegate.Remove(this.Completed, completedHandler);
         }
         if (errorHandler != null)
         {
             errorHandler(ex);
         }
     }
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (lstCountries.SelectedItems.Count == 0 && lstSystems.SelectedItems.Count == 0)
            {
                UserInfoHandler.ShowInfo("Please select the countries and/or systems you want to include into the project."); return;
            }

            if (txtProjectName.Text == string.Empty || txtProjectPath.Text == string.Empty)
            {
                UserInfoHandler.ShowError("Please select a valid Project Name and/or Project Path."); return;
            }
            projectPath = EMPath.AddSlash(EMPath.AddSlash(txtProjectPath.Text) + txtProjectName.Text);
            if (!EM_Helpers.IsValidFileName(projectPath))
            {
                UserInfoHandler.ShowInfo(projectPath + " is not a valid folder name for the new project."); return;
            }

            Cursor = Cursors.WaitCursor; bool undo = false;
            try
            {
                // first copy the whole EuromodFiles folder to the respective path, to then adapt the copy
                if (!XCopy.Folder(EM_AppContext.FolderEuromodFiles, txtProjectPath.Text, txtProjectName.Text))
                {
                    Cursor = Cursors.Default; return;
                }
                undo = true;

                // delete all unnecessary files and folders (but do not report or stop if any of this fails)
                EMPath emPath = new EMPath(EM_AppContext.FolderEuromodFiles);
                DeleteFolder(ReplacePath(emPath.GetFolderLog()));
                ClearFolder(ReplacePath(EM_AppContext.FolderOutput));
                ClearFolder(ReplacePath(emPath.GetFolderTemp()));
                DeleteFile(ReplacePath(Path.Combine(emPath.GetFolderConfig(true), "VersionControl.xml")));

                string        folderCountries = ReplacePath(EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles));
                List <string> selCountries    = new List <string>(); foreach (var item in lstCountries.SelectedItems)
                {
                    selCountries.Add(item.ToString().ToLower());
                }
                ClearFolder(folderCountries, selCountries);

                // delete all unnecessary systems
                List <string> selSystems = null;
                if (lstSystems.SelectedItems.Count > 0 && lstSystems.SelectedItems.Count != lstSystems.Items.Count)
                {
                    selSystems = new List <string>(); foreach (var item in lstSystems.SelectedItems)
                    {
                        selSystems.Add(item.ToString().ToLower());
                    }
                }
                foreach (string cc in selCountries)
                {
                    DeleteFile(EMPath.AddSlash(projectPath + cc) + cc + "_in_use.txt");

                    if (selSystems == null)
                    {
                        continue;                     // if all system/years are selected or nothing is selected, assume that user does not want to "reduce" systems
                    }
                    Country             country = new Country(cc);
                    CountryConfigFacade ccf     = country.GetCountryConfigFacade(true, folderCountries + country._shortName);
                    DataConfigFacade    dcf     = country.GetDataConfigFacade(true, folderCountries + country._shortName);

                    List <CountryConfig.SystemRow> delSystems = new List <CountryConfig.SystemRow>();
                    foreach (CountryConfig.SystemRow system in ccf.GetSystemRows())
                    {
                        if (radShowSystems.Checked)
                        {
                            if (!selSystems.Contains(system.Name.ToLower()))
                            {
                                delSystems.Add(system);
                            }
                        }
                        else
                        {
                            string systemYear = system.Year == null || system.Year == string.Empty ? EM_Helpers.ExtractSystemYear(system.Name) : system.Year;
                            if (!selSystems.Contains(systemYear))
                            {
                                delSystems.Add(system);
                            }
                        }
                    }

                    List <DataConfig.DBSystemConfigRow> delDBSysCons = new List <DataConfig.DBSystemConfigRow>();
                    List <string> delSystemIds = (from d in delSystems select d.ID).ToList();
                    foreach (DataConfig.DataBaseRow dataSet in dcf.GetDataBaseRows())
                    {
                        foreach (DataConfig.DBSystemConfigRow dbSystemConfig in dcf.GetDBSystemConfigRows(dataSet.ID))
                        {
                            if (delSystemIds.Contains(dbSystemConfig.SystemID))
                            {
                                delDBSysCons.Add(dbSystemConfig);
                            }
                        }
                    }

                    foreach (CountryConfig.SystemRow delSystem in delSystems)
                    {
                        delSystem.Delete();
                    }
                    foreach (DataConfig.DBSystemConfigRow delDBSysCon in delDBSysCons)
                    {
                        delDBSysCon.Delete();
                    }

                    country.WriteXML(folderCountries + country._shortName);
                }
                UserInfoHandler.ShowSuccess("Successfully created project folder " + projectPath + ".");
                Close();
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowError(exception.Message);
                if (undo)
                {
                    try { if (Directory.Exists(projectPath))
                          {
                              Directory.Delete(projectPath, true);
                          }
                    } catch { }
                }
            }
            Cursor = Cursors.Default;
        }
Example #10
0
        protected override Command CreateCommand()
        {
            var result = new XCopy();

            return result;
        }
Example #11
0
    private void OnAck_PassCopy(MessageRecv obj)
    {
        System.IO.MemoryStream ms  = new System.IO.MemoryStream(obj.Data);
        AckPassCopy            ack = Serializer.Deserialize <AckPassCopy>(ms);
        int chapter  = ack.Chapter;
        int copyID   = ack.CopyID;
        int copyType = ack.CopyType;
        int starNum  = ack.StarNum;

        XCopy copy;

        if (!DataDBSCopy.ContainsKey(copyID))
        {
            copy         = new XCopy();
            copy.Id      = copyID;
            copy.StarNum = starNum;
        }
        else
        {
            copy = DataDBSCopy.GetDataById(copyID);
            if (copy.StarNum < starNum)
            {
                copy.StarNum = starNum;
            }
        }
        DataDBSCopy.Update(copyID, copy);
        DCopy copyDB = ReadCfgCopy.GetDataById(copyID);

        GTDataManager.Instance.UseAction(copyDB.CostActionId, copyDB.CostActionNum);
        int   key = (int)copyType;
        XRaid raid;

        if (!DataDBSRaid.ContainsKey(key))
        {
            raid = new XRaid();
        }
        else
        {
            raid = DataDBSRaid.GetDataById(key);
        }

        raid.MaxChapter = chapter;
        raid.MaxCopyId  = copyID;
        raid.Id         = key;
        DataDBSRaid.Update(key, raid);

        if (starNum > 0)
        {
            XCharacter role = RoleModule.Instance.GetCurPlayer();
            RoleService.Instance.TryAddRoleExp(copyDB.GetExpRatio * role.Level);

            GTDataManager.Instance.AddMoney(copyDB.GetMoneyId, copyDB.GetMoneyRatio * role.Level);
            GTDataManager.Instance.UseAction(copyDB.CostActionId, copyDB.CostActionNum);
            List <KStruct> list = AwardModule.Instance.GetAwardDataByID(copyDB.AwardId);
            if (list != null)
            {
                GTDataManager.Instance.AddNewItemList(list, false);
            }
        }

        GTEventCenter.FireEvent(GTEventID.TYPE_PASS_COPY);
    }
Example #12
0
        static void Generate_BackgroundEventHandler(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            if (backgroundWorker.CancellationPending)
            {
                e.Cancel = true; return;
            }                                                                      //user pressed Cancel button: stop the process and allow progress indicator to set dialog result to Cancel

            //assess the name of the new EuromodFiles-folder in accordance to the version number
            DirectoryInfo sourceFolder = new DirectoryInfo(EM_AppContext.FolderEuromodFiles);
            string        folderEMF    = "EuromodFiles_" + _publicVersionNumber;

            if (!EM_Helpers.IsValidFileName(folderEMF))
            {
                UserInfoHandler.ShowInfo(folderEMF + " is not a valid folder name. Please change the version number.");
                e.Cancel = true; return;
            }

            //first copy the whole EuromodFiles folder to the respective path
            if (!XCopy.Folder(EM_AppContext.FolderEuromodFiles, _publicVersionPath, folderEMF))
            {
                e.Cancel = true; return;
            }

            string fullPublicPath = _publicVersionPath + EMPath.AddSlash(folderEMF);

            //then adapt the copy
            string folderCountries =
                EMPath.AddSlash( //at the new path assess the folder that contains the files (usually EuromodFiles)
                    EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath));

            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();

                //remove private systems, policies and datasets of each country
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Cancel = true; return;
                    }                                                                      //user pressed Cancel button: see above

                    Country             country             = countries[i];
                    CountryConfigFacade countryConfigFacade = country.GetCountryConfigFacade(true, folderCountries + country._shortName);
                    DataConfigFacade    dataConfigFacade    = country.GetDataConfigFacade(true, folderCountries + country._shortName);

                    //assess which systems, policies and datasets are private
                    List <CountryConfig.SystemRow>    privateSystems    = new List <CountryConfig.SystemRow>();    //systems
                    List <CountryConfig.PolicyRow>    privatePolicies   = new List <CountryConfig.PolicyRow>();    //policies
                    List <CountryConfig.FunctionRow>  privateFunctions  = new List <CountryConfig.FunctionRow>();  //functions
                    List <CountryConfig.ParameterRow> privateParameters = new List <CountryConfig.ParameterRow>(); //parameters
                    List <string> privateSystemIDs = new List <string>();                                          //necessary for afterwards identifying database-connections of private systems
                    foreach (CountryConfig.SystemRow system in countryConfigFacade.GetSystemRows())
                    {
                        if (system.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateSystems.Add(system);
                            privateSystemIDs.Add(system.ID);
                        }
                        else
                        {
                            foreach (CountryConfig.PolicyRow policy in system.GetPolicyRows())
                            {
                                if (policy.Private == DefPar.Value.YES)
                                {
                                    privatePolicies.Add(policy);
                                }
                                else
                                {
                                    if (policy.PrivateComment != null && policy.PrivateComment != string.Empty)
                                    {
                                        policy.PrivateComment = string.Empty; //remove private policy-comment if there is any
                                    }
                                    foreach (CountryConfig.FunctionRow function in policy.GetFunctionRows())
                                    {
                                        if (function.Private == DefPar.Value.YES)
                                        {
                                            privateFunctions.Add(function);
                                        }
                                        else
                                        {
                                            if (function.PrivateComment != null && function.PrivateComment != string.Empty)
                                            {
                                                function.PrivateComment = string.Empty; //remove private function-comment if there is any
                                            }
                                            foreach (CountryConfig.ParameterRow parameter in function.GetParameterRows())
                                            {
                                                if (parameter.Private == DefPar.Value.YES)
                                                {
                                                    privateParameters.Add(parameter);
                                                }
                                                else if (parameter.PrivateComment != null && parameter.PrivateComment != string.Empty)
                                                {
                                                    parameter.PrivateComment = string.Empty; //remove private parameter-comment if there is any
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    List <DataConfig.DataBaseRow>       privateDataSets        = new List <DataConfig.DataBaseRow>();       //datasets
                    List <DataConfig.DBSystemConfigRow> privateDBSystemConfigs = new List <DataConfig.DBSystemConfigRow>(); //database-connections of private systems
                    foreach (DataConfig.DataBaseRow dataSet in dataConfigFacade.GetDataBaseRows())
                    {
                        if (dataSet.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateDataSets.Add(dataSet);
                        }
                        else
                        {
                            foreach (DataConfig.DBSystemConfigRow dbSystemConfig in dataConfigFacade.GetDBSystemConfigRows(dataSet.ID))
                            {
                                if (privateSystemIDs.Contains(dbSystemConfig.SystemID))
                                {
                                    privateDBSystemConfigs.Add(dbSystemConfig);
                                }
                            }
                        }
                    }

                    //remove user-set node colors
                    countryConfigFacade.RemoveAllNodeColors();

                    //restore or install default base-system-colouring
                    countryConfigFacade.setAutomaticConditionalFormatting(true);

                    //remove private systems
                    if (countryConfigFacade.GetCountryRow().Private == DefPar.Value.YES || //if country is private or
                        privateSystems.Count == countryConfigFacade.GetSystemRows().Count) //there are no systems left, delete country
                    {
                        Directory.Delete(folderCountries + country._shortName, true);
                        country.SetCountryConfigFacade(null);
                        country.SetDataConfigFacade(null);
                        continue;
                    }
                    else //otherwise delete private systems
                    {
                        foreach (CountryConfig.SystemRow privateSystem in privateSystems)
                        {
                            privateSystem.Delete();
                        }
                    }

                    //remove private parameters
                    foreach (CountryConfig.ParameterRow privateParameter in privateParameters)
                    {
                        privateParameter.Delete();
                    }

                    //remove private functions
                    foreach (CountryConfig.FunctionRow privateFunction in privateFunctions)
                    {
                        privateFunction.Delete();
                    }

                    //remove private policies
                    foreach (CountryConfig.PolicyRow privatePolicy in privatePolicies)
                    {
                        privatePolicy.Delete();
                    }

                    //remove private datasets
                    foreach (DataConfig.DataBaseRow privateDataSet in privateDataSets)
                    {
                        privateDataSet.Delete();
                    }

                    //remove database-connections of private systems
                    foreach (DataConfig.DBSystemConfigRow privateDBSystemConfig in privateDBSystemConfigs)
                    {
                        privateDBSystemConfig.Delete();
                    }

                    country.WriteXML(folderCountries + country._shortName);
                    country.SetCountryConfigFacade(null);
                    country.SetDataConfigFacade(null);

                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 80.0));
                }

                //remove private add-ons
                string folderAddOns = EMPath.AddSlash( //at the new path assess the folder that contains the files (usually EuromodFiles)
                    EMPath.Folder_AddOns(EM_AppContext.FolderEuromodFiles).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath));
                foreach (Country addOn in CountryAdministrator.GetAddOns())
                {
                    bool oldStyle = CountryAdministrator.ConsiderOldAddOnFileStructure(true);
                    CountryConfigFacade addOnConfigFacade = addOn.GetCountryConfigFacade(true, folderAddOns + (oldStyle ? string.Empty : addOn._shortName));
                    if (addOnConfigFacade.GetCountryRow().Private != DefPar.Value.YES)
                    {
                        continue;
                    }
                    if (oldStyle)
                    {
                        File.Delete(folderAddOns + addOn._shortName + ".xml");
                    }
                    else
                    {
                        Directory.Delete(folderAddOns + addOn._shortName, true);
                    }
                    addOn.SetCountryConfigFacade(null);
                }

                // remove the "other" column from the variables file
                string          pathVarConfig = new EMPath(EM_AppContext.FolderEuromodFiles).GetVarFilePath(true).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                VarConfigFacade vcf           = new VarConfigFacade(pathVarConfig);
                if (vcf.LoadVarConfig())
                {
                    foreach (VarConfig.CountryLabelRow r in
                             from l in vcf._varConfig.CountryLabel where l.Country.ToLower() == "other" select l)
                    {
                        r.Delete();
                    }
                    vcf.Commit(); vcf.WriteXML(pathVarConfig);
                }

                if (backgroundWorker.CancellationPending)
                {
                    e.Cancel = true; return;
                }                                                                      //user pressed Cancel button: see above

                //change version number
                string txtVersionPath = EMPath.Folder_Config(EM_AppContext.FolderEuromodFiles) + "EuromodVersion.txt";
                txtVersionPath = txtVersionPath.Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                using (StreamWriter versionFile = new StreamWriter(txtVersionPath))
                {
                    versionFile.WriteLine(_publicVersionNumber);
                    versionFile.WriteLine("PUBLIC VERSION");
                }

                //remove private rows from log file
                string logFile = new EMPath(EM_AppContext.FolderEuromodFiles).GetEmLogFilePath(); // determine the path of the em_log-file in the public folder
                logFile = logFile.Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                backgroundWorker.ReportProgress(100);
                if (File.Exists(logFile))
                {
                    AdaptLogFile(logFile);
                }

                //take care to not have any "xx_in_use.txt" files in the release
                try
                {
                    foreach (string inUseFile in Directory.GetFiles(fullPublicPath, "*_in_use.txt", SearchOption.AllDirectories))
                    {
                        File.Delete(inUseFile);
                    }
                }
                catch (Exception exception)
                {
                    //do nothing if this fails
                    UserInfoHandler.RecordIgnoredException("PublicVersion.Generate_BackgroundEventHandler", exception);
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
                e.Cancel = true; //stop the process and allow progress indicator to set dialog result to Cancel
            }
        }