示例#1
0
        internal static MDKProjectPaths Import(MDKProjectProperties.LegacyProjectScriptInfo_1_1 scriptInfo, string pathsFileName)
        {
            if (!scriptInfo.IsValid)
            {
                return(null);
            }
            var paths = new MDKProjectPaths(pathsFileName, true)
            {
                GameBinPath = scriptInfo.GameBinPath,
                InstallPath = scriptInfo.InstallPath,
                OutputPath  = scriptInfo.OutputPath
            };

            foreach (var reference in DefaultAssemblyReferences)
            {
                paths.AssemblyReferences.Add(reference);
            }
            foreach (var reference in DefaultAnalyzerReferences)
            {
                paths.AnalyzerReferences.Add(reference);
            }
            paths.Commit();
            paths.Version = scriptInfo.Version;
            return(paths);
        }
示例#2
0
 MDKProjectProperties(string fileName, string name, MDKProjectOptions options, MDKProjectPaths paths)
 {
     FileName = fileName;
     Name     = name;
     Options  = options;
     if (Options != null)
     {
         Options.PropertyChanged += OnOptionsPropertyChanged;
     }
     Paths = paths;
     if (Paths != null)
     {
         Paths.PropertyChanged += OnPathsPropertyChanged;
     }
 }
示例#3
0
        /// <summary>
        /// Loads script information from the given project file.
        /// </summary>
        /// <param name="projectFileName">The file name of this project</param>
        /// <param name="projectName">The display name of this project</param>
        /// <returns></returns>
        public static MDKProjectProperties Load([NotNull] string projectFileName, string projectName = null, Action <string> echo = null)
        {
            if (string.IsNullOrEmpty(projectFileName))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(projectFileName));
            }

            if (!File.Exists(projectFileName) || Regex.IsMatch(projectFileName, @"\w+://"))
            {
                echo?.Invoke($"{projectFileName} does not exist, or it's a network file (not supported)");
                return(new MDKProjectProperties(projectFileName, null, null, null));
            }

            var fileName = Path.GetFullPath(projectFileName);
            var name     = projectName ?? Path.GetFileNameWithoutExtension(projectFileName);
            var legacyOptionsFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options"));
            var mdkOptionsFileName    = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options.props"));
            var mdkPathsFileName      = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.paths.props"));

            MDKProjectOptions options = null;
            MDKProjectPaths   paths   = null;

            if (File.Exists(mdkOptionsFileName) /* && File.Exists(mdkPathsFileName)*/)
            {
                options = MDKProjectOptions.Load(mdkOptionsFileName);
                paths   = MDKProjectPaths.Load(mdkPathsFileName);

                echo?.Invoke($"{projectName ?? projectFileName} is a valid MDK project.");
                return(new MDKProjectProperties(projectFileName, name, options, paths));
            }

            if (File.Exists(legacyOptionsFileName))
            {
                echo?.Invoke($"{projectName ?? projectFileName} is a legacy MDK project.");
                ImportLegacy_1_1(projectFileName, ref options, mdkOptionsFileName, ref paths, mdkPathsFileName);
                if (options != null && paths != null)
                {
                    return(new MDKProjectProperties(projectFileName, name, options, paths));
                }
            }

            echo?.Invoke($"{projectName ?? projectFileName} not an MDK project.");
            return(new MDKProjectProperties(projectFileName, null, null, null));
        }
示例#4
0
        /// <summary>
        /// Loads script information from the given project file.
        /// </summary>
        /// <param name="projectFileName">The file name of this project</param>
        /// <param name="projectName">The display name of this project</param>
        /// <returns></returns>
        public static MDKProjectProperties Load([NotNull] string projectFileName, string projectName = null)
        {
            if (string.IsNullOrEmpty(projectFileName))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(projectFileName));
            }

            if (!File.Exists(projectFileName) || Regex.IsMatch(projectFileName, @"\w+://"))
            {
                return(new MDKProjectProperties(projectFileName, null, null, null));
            }

            var fileName = Path.GetFullPath(projectFileName);
            var name     = projectName ?? Path.GetFileNameWithoutExtension(projectFileName);
            var legacyOptionsFileName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options"));
            var mdkOptionsFileName    = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.options.props"));
            var mdkPathsFileName      = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(fileName) ?? ".", @"mdk\mdk.paths.props"));

            MDKProjectOptions options = null;
            MDKProjectPaths   paths   = null;

            if (File.Exists(mdkOptionsFileName) /* && File.Exists(mdkPathsFileName)*/)
            {
                options = MDKProjectOptions.Load(mdkOptionsFileName);
                paths   = MDKProjectPaths.Load(mdkPathsFileName);

                return(new MDKProjectProperties(projectFileName, name, options, paths));
            }

            if (File.Exists(legacyOptionsFileName))
            {
                ImportLegacy_1_1(projectFileName, ref options, mdkOptionsFileName, ref paths, mdkPathsFileName);
                if (options != null && paths != null)
                {
                    return(new MDKProjectProperties(projectFileName, name, options, paths));
                }
            }

            return(new MDKProjectProperties(projectFileName, null, null, null));
        }
示例#5
0
 static partial void ImportLegacy_1_1(string legacyOptionsFileName, ref MDKProjectOptions options, string optionsFileName, ref MDKProjectPaths paths, string pathsFileName);
示例#6
0
        /// <summary>
        /// Loads path information for an MDK project
        /// </summary>
        /// <param name="fileName">The file name of this project paths file</param>
        /// <returns></returns>
        public static MDKProjectPaths Load([NotNull] string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(fileName));
            }
            fileName = Path.GetFullPath(fileName);
            if (!File.Exists(fileName))
            {
                return(new MDKProjectPaths(fileName, false));
            }
            try
            {
                using (var streamReader = File.OpenText(fileName))
                {
                    var readerSettings = new XmlReaderSettings
                    {
                        IgnoreWhitespace = true
                    };
                    var xmlReader = XmlReader.Create(streamReader, readerSettings);
                    var document  = XDocument.Load(xmlReader);
                    var nameTable = xmlReader.NameTable;
                    if (nameTable == null)
                    {
                        return(new MDKProjectPaths(fileName, false));
                    }
                    var nsm = new XmlNamespaceManager(nameTable);
                    nsm.AddNamespace("m", Xmlns);

                    // Check if this is a template options file
                    var versionElement = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKVersion", nsm);
                    var versionStr     = (string)versionElement;
                    if (versionStr == "$MDKVersion$")
                    {
                        return(new MDKProjectPaths(fileName, false));
                    }
                    Version.TryParse(versionStr, out var version);

                    var gameBinPathElement = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKGameBinPath", nsm);
                    var gameBinPath        = ((string)gameBinPathElement)?.Trim();

                    var installPathElement = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKInstallPath", nsm);
                    var installPath        = ((string)installPathElement)?.Trim();

                    var outputPathElement = document.XPathSelectElement("./m:Project/m:PropertyGroup/m:MDKOutputPath", nsm);
                    var outputPath        = ((string)outputPathElement)?.Trim();

                    var paths = new MDKProjectPaths(fileName, true)
                    {
                        Version     = version,
                        GameBinPath = gameBinPath,
                        InstallPath = installPath,
                        OutputPath  = outputPath,
                        HasChanges  = false
                    };
                    foreach (var reference in DefaultAssemblyReferences)
                    {
                        paths.AssemblyReferences.Add(reference);
                    }
                    foreach (var reference in DefaultAnalyzerReferences)
                    {
                        paths.AnalyzerReferences.Add(reference);
                    }
                    return(paths);
                }
            }
            catch (Exception e)
            {
                throw new MDKProjectPropertiesException($"An error occurred while attempting to load project information from {fileName}.", e);
            }
        }