예제 #1
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            GUIToSettings();
            Settings.SaveToFile(SettingsFilename, Settings);

            Close();

            NewSettingsApplied?.Invoke();

            if (chkDeleteLinksandModFolder.Checked)
            {
                var linkUtility = new libDCS_Mod_app.Links.Providers.JunctionUtility();
                var linkManager = new LinkManager(liveriesFolderSettings.Folder, FolderSettings.Folder, linkUtility);
                linkManager.DeleteCurrentLinks();

                DeleteEmptyDirs(liveriesFolderSettings.Folder);


                void DeleteEmptyDirs(string dir)
                {
                    if (String.IsNullOrEmpty(dir))
                    {
                        throw new ArgumentException(
                                  "Starting directory is a null reference or an empty string",
                                  "dir");
                    }

                    try
                    {
                        foreach (var d in Directory.EnumerateDirectories(dir))
                        {
                            DeleteEmptyDirs(d);
                        }

                        var entries = Directory.EnumerateFileSystemEntries(dir);

                        if (!entries.Any())
                        {
                            try
                            {
                                Directory.Delete(dir);
                            }
                            catch (UnauthorizedAccessException) { }
                            catch (DirectoryNotFoundException) { }
                        }
                    }
                    catch (UnauthorizedAccessException) { }
                }

                try
                {
                    Directory.Delete(FolderSettings.Folder, true);
                    bool directoryExists = Directory.Exists(FolderSettings.Folder);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Unknown error while Deleting Files", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #2
0
        private void Rebuildbutton_Click(object sender, EventArgs e)
        {
            if (liveriesFolder == null || ModFolder == null)
            {
                return;
            }

            if (sender != null)
            {
                //This is a user call

                if (verifyTask != null && !verifyTask.IsCompleted)
                {
                    return;
                }

                if (downloadTask != null && !downloadTask.IsCompleted)
                {
                    return;
                }
            }

            try
            {
                //TODO: Based on the user's settings, use Symlinks or Junctions.
                //Junctions don't require admin rights, but can only reference local drives.
                //Symlinks require admin rights, but can reference network drivers.

                var linkUtility = new JunctionUtility();
                var linkManager = new LinkManager(liveriesFolder, ModFolder, linkUtility);
                linkManager.DeleteCurrentLinks();
                linkManager.CreateLinks();

                if (sender != null)
                {
                    SetCurrentAction("Finished rebuilding links.");
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("0x80070522"))
                {
                    MessageBox.Show("To create symlinks, the program must be run as Adminstrator", "Error rebuilding symlinks", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.ToString(), "Unknown error while rebuilding links", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }