public void MyTestInitialize()
        {
            // File System Layout
            //
            // Name             Size (bytes)    Size (sectors)  Offset (bytes)  Offset (sectors)
            // Boot Sector      512             1               0               0
            // FSD              512             1               512             1
            // CAT              3160            7               1024            2
            // DA               3235840         6320            4608            9
            //
            // Boot Sector      2048            1               0               0
            // FSD              2048            1               2048            1
            // CAT              3160            2               4096            2
            // DA               12943360        6320            8192            4

            Context1 = new FileSystemDefinition
            {
                SectorSizeInBytes    = 512,
                ClusterSizeInSectors = 8,
                NumberOfCatEntries   = 790
            };

            Context2 = new FileSystemDefinition
            {
                SectorSizeInBytes    = 2048,
                ClusterSizeInSectors = 8,
                NumberOfCatEntries   = 790
            };
        }
示例#2
0
 public BackupDir(FileSystemPath oldDir, string backupFolderPrefix)
 {
     myOldDir    = oldDir;
     myBackupDir = FileSystemDefinition.CreateTemporaryDirectory(null, backupFolderPrefix);
     myOldDir.CopyDirectory(myBackupDir);
     myOldDir.Delete();
 }
示例#3
0
 protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
 {
     return(control =>
     {
         var file = FileSystemDefinition.CreateTemporaryFile(extensionWithDot: ".txt");
         file.WriteTextStream(writer =>
         {
             solution.GetComponent <AttributedTypesCache>().Dump(writer);
         });
         Process.Start(file.FullPath);
     });
 }
示例#4
0
        private async Task InstallPluginInGame(Lifetime lifetime, UnrealPluginInstallInfo unrealPluginInstallInfo,
                                               Property <double> progress)
        {
            var backupDir = FileSystemDefinition.CreateTemporaryDirectory(null, TMP_PREFIX);

            using var deleteTempFolders = new DeleteTempFolders(backupDir.Directory);

            var backupAllPlugins = BackupAllPlugins(unrealPluginInstallInfo);
            var success          = true;
            var size             = unrealPluginInstallInfo.ProjectPlugins.Count;
            var range            = 1.0 / size;

            for (int i = 0; i < unrealPluginInstallInfo.ProjectPlugins.Count; i++)
            {
                progress.Value = range * i;
                var installDescription = unrealPluginInstallInfo.ProjectPlugins[i];
                try
                {
                    if (await InstallPlugin(lifetime, installDescription, installDescription.UprojectFilePath, progress,
                                            range))
                    {
                        continue;
                    }
                }
                catch (OperationCanceledException)
                {
                    // Operation was cancelled, don't need to do anything, fallback to break case
                }

                success = false;
                break;
            }

            if (success)
            {
                unrealPluginInstallInfo.EnginePlugin.IsPluginAvailable = false;
            }
            else
            {
                foreach (var backupAllPlugin in backupAllPlugins)
                {
                    backupAllPlugin.Restore();
                }
            }

            myUnrealHost.myModel.InstallPluginFinished(success);
        }
示例#5
0
        private async Task InstallPluginInEngine(Lifetime lifetime, UnrealPluginInstallInfo unrealPluginInstallInfo,
                                                 IProperty <double> progress)
        {
            var backupDir = FileSystemDefinition.CreateTemporaryDirectory(null, TMP_PREFIX);

            using var deleteTempFolders = new DeleteTempFolders(backupDir.Directory);

            var backupAllPlugins = BackupAllPlugins(unrealPluginInstallInfo);

            progress.Value = 0.0;
            bool success;

            try
            {
                success = await InstallPlugin(lifetime, unrealPluginInstallInfo.EnginePlugin,
                                              unrealPluginInstallInfo.ProjectPlugins.First().UprojectFilePath, progress, 1.0);
            }
            catch (OperationCanceledException)
            {
                success = false;
            }

            if (!success)
            {
                foreach (var backupAllPlugin in backupAllPlugins)
                {
                    backupAllPlugin.Restore();
                }
            }
            else
            {
                foreach (var installDescription in unrealPluginInstallInfo.ProjectPlugins)
                {
                    installDescription.IsPluginAvailable = false;
                }
            }

            myUnrealHost.myModel.InstallPluginFinished(success);
        }
示例#6
0
        private async Task <bool> InstallPlugin(Lifetime lifetime,
                                                UnrealPluginInstallInfo.InstallDescription installDescription,
                                                FileSystemPath uprojectFile, IProperty <double> progressProperty, double range)
        {
            using var def = new LifetimeDefinition();
            var ZIP_STEP     = 0.1 * range;
            var PATCH_STEP   = 0.1 * range;
            var BUILD_STEP   = 0.6 * range;
            var REFRESH_STEP = 0.1 * range;

            var pluginRootFolder = installDescription.UnrealPluginRootFolder;

            var editorPluginPathFile = myPathsProvider.PathToPackedPlugin;
            var pluginTmpDir         = FileSystemDefinition.CreateTemporaryDirectory(null, TMP_PREFIX);

            def.Lifetime.OnTermination(() => { pluginTmpDir.Delete(); });
            try
            {
                ZipFile.ExtractToDirectory(editorPluginPathFile.FullPath, pluginTmpDir.FullPath);
                progressProperty.Value += ZIP_STEP;
            }
            catch (Exception exception)
            {
                myLogger.Warn(exception, $"[UnrealLink]: Couldn't extract {editorPluginPathFile} to {pluginTmpDir}");

                const string unzipFailTitle = "Failed to unzip new RiderLink plugin";
                var          unzipFailText  =
                    $"Failed to unzip new version of RiderLink ({editorPluginPathFile.FullPath}) to user folder ({pluginTmpDir.FullPath})\n" +
                    "Try restarting Rider in administrative mode";

                myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(unzipFailTitle, ContentType.Error));
                myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(unzipFailText, ContentType.Error));
                return(false);
            }

            lifetime.ToCancellationToken().ThrowIfCancellationRequested();

            var upluginFile       = UnrealPluginDetector.GetPathToUpluginFile(pluginTmpDir);
            var pluginBuildOutput = FileSystemDefinition.CreateTemporaryDirectory(null, TMP_PREFIX);

            def.Lifetime.OnTermination(() => { pluginBuildOutput.Delete(); });
            var buildProgress = progressProperty.Value;
            var isPluginBuilt = await BuildPlugin(lifetime, upluginFile,
                                                  pluginBuildOutput,
                                                  uprojectFile, value => progressProperty.SetValue(buildProgress + value *BUILD_STEP));

            if (!isPluginBuilt)
            {
                myLogger.Warn($"Failed to build RiderLink for any available project");
                const string failedBuildText = "Failed to build RiderLink plugin";
                myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(failedBuildText, ContentType.Error));
                return(false);
            }

            progressProperty.Value = buildProgress + BUILD_STEP;

            lifetime.ToCancellationToken().ThrowIfCancellationRequested();

            if (!PatchUpluginFileAfterInstallation(pluginBuildOutput))
            {
                const string failedToPatch   = "Failed to patch RiderLink.uplugin";
                var          failedPatchText = "Failed to set `EnableByDefault` to true in RiderLink.uplugin\n" +
                                               "You need to manually enable RiderLink in UnrealEditor";
                myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(failedToPatch, ContentType.Normal));
                myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(failedPatchText, ContentType.Normal));
            }

            progressProperty.Value += PATCH_STEP;

            lifetime.ToCancellationToken().ThrowIfCancellationRequested();

            pluginRootFolder.CreateDirectory().DeleteChildren();
            pluginBuildOutput.Copy(pluginRootFolder);
            progressProperty.Value += REFRESH_STEP;

            installDescription.IsPluginAvailable = true;
            installDescription.PluginVersion     = myPathsProvider.CurrentPluginVersion;

            const string title = "RiderLink plugin installed";
            var          text  = $"RiderLink plugin was installed to: {pluginRootFolder}";

            myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(title, ContentType.Normal));
            myUnrealHost.myModel.RiderLinkInstallMessage(new InstallMessage(text, ContentType.Normal));

            var notification = new NotificationModel(title, text, true, RdNotificationEntryType.INFO,
                                                     new List <NotificationHyperlink>());

            mySolution.Locks.ExecuteOrQueue(Lifetime, "UnrealLink.InstallPlugin",
                                            () => { myNotificationsModel.Notification(notification); });

            mySolution.Locks.ExecuteOrQueueReadLock(Lifetime, "UnrealLink.RegenerateProjectFiles", () =>
            {
                var cppUe4SolutionDetector = mySolution.GetComponent <CppUE4SolutionDetector>();
                if (cppUe4SolutionDetector.SupportRiderProjectModel != CppUE4ProjectModelSupportMode.UprojectOpened)
                {
                    RegenerateProjectFiles(uprojectFile);
                }
            });
            return(true);
        }