Пример #1
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);
                }
            }
        }