Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
        }