Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userProj"></param>
        /// <param name="projectModel"></param>
        /// <param name="project"></param>
        /// <param name="dteProject"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public static string SetReferencePaths(Project userProj, ProjectModel projectModel, Project project, EnvDTE.Project dteProject)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string beatSaberDir = BSMTSettingsManager.Instance.CurrentSettings.ChosenInstallPath;
            string userProjPath = userProj?.FullPath ?? project.FullPath + ".user";

            userProj = userProj ?? ProjectCollection.GlobalProjectCollection.GetLoadedProjects(userProjPath).FirstOrDefault();
            bool userFileCreated = false;

            if (userProj == null)
            {
                if (!File.Exists(userProjPath))
                {
                    File.WriteAllText(userProjPath, CreateUserProject(beatSaberDir));
                    userProj        = ProjectCollection.GlobalProjectCollection.LoadProject(userProjPath);
                    userFileCreated = true;
                    //dteProject.ProjectItems.AddFromFile(userProjPath);
                }
                if (File.Exists(userProjPath))
                {
                    userProj = ProjectCollection.GlobalProjectCollection.LoadProject(userProjPath);
                }
            }

            string          hintPathsStr = GetReferencePathString(beatSaberDir) ?? throw new ArgumentException("Error setting ReferencePath, chosen install path is null or empty.");
            ProjectProperty prop         = userProj?.SetProperty("ReferencePath", hintPathsStr) ?? throw new InvalidOperationException("Could not access or create csproj.user file.");

            userProj.MarkDirty();
            userProj.Save();
            project.MarkDirty();
            project.ReevaluateIfNecessary();
            return($"Setting ReferencePath in {projectModel.ProjectName} to \n{prop.EvaluatedValue}{(userFileCreated ? "\n\nYou may need to reload the project." : "")}");
        }
Ejemplo n.º 2
0
        public static string SetBeatSaberDir(Project userProj, ProjectModel projectModel, Project project, EnvDTE.Project dteProject)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string beatSaberDir    = null;
            string userProjPath    = null;
            bool   userFileCreated = false;

            try
            {
                beatSaberDir = BSMTSettingsManager.Instance.CurrentSettings.ChosenInstallPath;
                userProjPath = userProj?.FullPath ?? project.FullPath + ".user";
                userProj     = userProj ?? ProjectCollection.GlobalProjectCollection.GetLoadedProjects(userProjPath).FirstOrDefault();
                if (userProj == null)
                {
                    if (!File.Exists(userProjPath))
                    {
                        File.WriteAllText(userProjPath, CreateUserProject(beatSaberDir));
                        userProj        = ProjectCollection.GlobalProjectCollection.LoadProject(userProjPath);
                        userFileCreated = true;
                        //dteProject.ProjectItems.AddFromFile(userProjPath);
                    }
                    if (File.Exists(userProjPath))
                    {
                        userProj = ProjectCollection.GlobalProjectCollection.LoadProject(userProjPath);
                    }
                }
                ProjectProperty prop = userProj?.SetProperty("BeatSaberDir", beatSaberDir) ?? throw new InvalidOperationException("Could not access or create csproj.user file.");
                userProj.MarkDirty();
                userProj.Save();
                project.MarkDirty();
                project.ReevaluateIfNecessary();
                return($"Setting BeatSaberDir in {projectModel.ProjectName} to \n{prop.EvaluatedValue}{(userFileCreated ? "\n\nYou may need to reload the project." : "")}");
            }
            catch (Exception ex)
            {
                return($"Failed to set BeatSaberDir: {ex.Message}\nbeatSaberDir: '{beatSaberDir}'|userProjLoaded: {userProj != null}|userProjPath: '{userProjPath}'\n{ex.StackTrace}");
            }
        }