예제 #1
0
        public static CompilerInstallInfo AddPath(string path)
        {
            CompilerInstallInfo cinf = null;

            if (!string.IsNullOrEmpty(path))
            {
                FileInfo fi = new FileInfo(path);
                if (fi.Exists)
                {
                    path = fi.Directory.FullName;
                }
                if (path.IndexOf(':') == 1)
                {
                    path = path.Substring(2);
                }
                if (path.EndsWith(".exe"))
                {
                    path = path.Substring(0, path.LastIndexOf('\\'));
                }
                path = path.TrimEnd('\\');
                if (!paths.Contains(path))
                {
                    paths.Add(path.TrimEnd('\\'));
                }

                cinf = GetLocalDMDInstallation(path);
                if (cinf != null)
                {
                    localDMDInstallations = null;
                    GetLocalDMDInstallations();
                }
            }
            return(cinf);
        }
예제 #2
0
        public static bool IsValidDMDInstallForVersion(int majorVersion, string path)
        {
            bool isValid = false;
            CompilerInstallInfo installInfo = LocalCompiler.AddPath(path);

            if (installInfo != null)
            {
                isValid = (installInfo.VersionInfo.Major == majorVersion);
            }

            return(isValid);
        }
예제 #3
0
        private static CompilerInstallInfo GetLocalDMDInstallation(string path, ref Version v1, ref Version v2)
        {
            CompilerInstallInfo cii = null;

            if (File.Exists(path))
            {
                cii = new CompilerInstallInfo(new FileInfo(path));

                if ((cii.VersionInfo.Major == 1) &&
                    ((v1 == null) || (v1 > cii.VersionInfo)))
                {
                    v1       = cii.VersionInfo;
                    latest1x = cii;
                }

                if ((cii.VersionInfo.Major == 2) &&
                    ((v2 == null) || (v2 > cii.VersionInfo)))
                {
                    v2       = cii.VersionInfo;
                    latest2x = cii;
                }
            }
            return(cii);
        }
예제 #4
0
        private static CompilerInstallInfo GetLocalDMDInstallation(string path, ref Version v1, ref Version v2)
        {
            CompilerInstallInfo cii = null;
            if (File.Exists(path))
            {
                cii = new CompilerInstallInfo(new FileInfo(path));

                if ((cii.VersionInfo.Major == 1) &&
                    ((v1 == null) || (v1 > cii.VersionInfo)))
                {
                    v1 = cii.VersionInfo;
                    latest1x = cii;
                }

                if ((cii.VersionInfo.Major == 2) &&
                    ((v2 == null) || (v2 > cii.VersionInfo)))
                {
                    v2 = cii.VersionInfo;
                    latest2x = cii;
                }
            }
            return cii;
        }
예제 #5
0
        private static void GetLocalDMDInstallations()
        {
            if (localDMDInstallations == null)
            {
                paths = new List<string>(POSSIBLE_LOCATIONS);
                localDMDInstallations = new List<CompilerInstallInfo>();

                if (DataFile.Exists)
                {
                    string[] lines = File.ReadAllLines(DataFile.FullName);
                    CompilerInstallInfo cii;
                    for (int i = 0; i < lines.Length; i++)
                    {
                        cii = new CompilerInstallInfo();
                        if (cii.FromString(lines[i]))
                        {
                            if ((cii.VersionInfo.Major == 1) && (latest1x == null || latest1x.VersionInfo < cii.VersionInfo)) latest1x = cii; 
                            else if ((cii.VersionInfo.Major == 2) && (latest2x == null || latest2x.VersionInfo < cii.VersionInfo)) latest2x = cii; 

                            localDMDInstallations.Add(cii);
                        }
                    }
                }
                else
                {
                    Version v1 = null, v2 = null;

                    foreach (string folder in DmdFoldersFromSystemPath)
                    {
                        string path = folder + COMPILER_EXE;
                        if (File.Exists(path))
                        {
                            CompilerInstallInfo inf = GetLocalDMDInstallation(path, ref v1, ref v2);
                            if (inf != null)
                            {
                                localDMDInstallations.Add(inf);
                            }
                        }
                    }

                    string reg1 = ReadRegKey(BASE_REG_KEY, DMD1_PATH_REG_KEY),
                        reg2 = ReadRegKey(BASE_REG_KEY, DMD2_PATH_REG_KEY),
                        reg3 = ReadRegKey(D_BASE_REG_KEY, D_INSTALL_PATH_REG_KEY);

                    if (reg1 != null) paths.Add(reg1);
                    if (reg2 != null) paths.Add(reg2);
                    if (reg3 != null) paths.Add(reg3);

                    string[] dirs = new string[] { 
                        Environment.GetEnvironmentVariable("PROGRAMFILES"),
                        Environment.GetEnvironmentVariable("PROGRAMFILES(X86)"),
                        Environment.GetEnvironmentVariable("APPDATA"),
                        Environment.GetEnvironmentVariable("USERPROFILE") };

                    DriveInfo[] drives = DriveInfo.GetDrives();
                    foreach (DriveInfo drive in drives)
                    {
                        if (drive.DriveType == DriveType.Fixed ||
                            drive.DriveType == DriveType.Removable)
                        {
                            foreach (string possibleLocation in paths)
                            {
                                string path = possibleLocation + RELATIVE_COMPILER_PATH + COMPILER_EXE;
                                if (path[1] != ':' && path[0] != '%') path = drive.Name.TrimEnd('\\') + path;

                                if (possibleLocation.IndexOf("%ENV%") >= 0)
                                {
                                    foreach (string dir in dirs)
                                    {
                                        string envPath = path.Replace("%ENV%", dir);
                                        CompilerInstallInfo inf = GetLocalDMDInstallation(envPath, ref v1, ref v2);
                                        if (inf != null)
                                        {
                                            localDMDInstallations.Add(inf);
                                        }
                                    }
                                }
                                else
                                {
                                    GetLocalDMDInstallation(path, ref v1, ref v2);
                                    CompilerInstallInfo inf = GetLocalDMDInstallation(path, ref v1, ref v2);
                                    if (inf != null)
                                    {
                                        localDMDInstallations.Add(inf);
                                    }
                                }
                            }
                        }
                    }


                    StringBuilder sb = new StringBuilder();
                    foreach (CompilerInstallInfo cii in localDMDInstallations) sb.Append(cii.ToString()).Append("\r\n");
                    File.WriteAllText(DataFile.FullName, sb.ToString());
                    //File.WriteAllText(@"C:\Users\Justin\Desktop\LocalInit_" + DateTime.Now.Ticks + ".txt", DateTime.Now.ToLongDateString());
                }
            }
        }
예제 #6
0
        private static void GetLocalDMDInstallations()
        {
            if (localDMDInstallations == null)
            {
                paths = new List <string>(POSSIBLE_LOCATIONS);
                localDMDInstallations = new List <CompilerInstallInfo>();

                if (DataFile.Exists)
                {
                    string[]            lines = File.ReadAllLines(DataFile.FullName);
                    CompilerInstallInfo cii;
                    for (int i = 0; i < lines.Length; i++)
                    {
                        cii = new CompilerInstallInfo();
                        if (cii.FromString(lines[i]))
                        {
                            if ((cii.VersionInfo.Major == 1) && (latest1x == null || latest1x.VersionInfo < cii.VersionInfo))
                            {
                                latest1x = cii;
                            }
                            else if ((cii.VersionInfo.Major == 2) && (latest2x == null || latest2x.VersionInfo < cii.VersionInfo))
                            {
                                latest2x = cii;
                            }

                            localDMDInstallations.Add(cii);
                        }
                    }
                }
                else
                {
                    Version v1 = null, v2 = null;

                    foreach (string folder in DmdFoldersFromSystemPath)
                    {
                        string path = folder + COMPILER_EXE;
                        if (File.Exists(path))
                        {
                            CompilerInstallInfo inf = GetLocalDMDInstallation(path, ref v1, ref v2);
                            if (inf != null)
                            {
                                localDMDInstallations.Add(inf);
                            }
                        }
                    }

                    string reg1 = ReadRegKey(BASE_REG_KEY, DMD1_PATH_REG_KEY),
                           reg2 = ReadRegKey(BASE_REG_KEY, DMD2_PATH_REG_KEY),
                           reg3 = ReadRegKey(D_BASE_REG_KEY, D_INSTALL_PATH_REG_KEY);

                    if (reg1 != null)
                    {
                        paths.Add(reg1);
                    }
                    if (reg2 != null)
                    {
                        paths.Add(reg2);
                    }
                    if (reg3 != null)
                    {
                        paths.Add(reg3);
                    }

                    string[] dirs = new string[] {
                        Environment.GetEnvironmentVariable("PROGRAMFILES"),
                        Environment.GetEnvironmentVariable("PROGRAMFILES(X86)"),
                        Environment.GetEnvironmentVariable("APPDATA"),
                        Environment.GetEnvironmentVariable("USERPROFILE")
                    };

                    DriveInfo[] drives = DriveInfo.GetDrives();
                    foreach (DriveInfo drive in drives)
                    {
                        if (drive.DriveType == DriveType.Fixed ||
                            drive.DriveType == DriveType.Removable)
                        {
                            foreach (string possibleLocation in paths)
                            {
                                string path = possibleLocation + RELATIVE_COMPILER_PATH + COMPILER_EXE;
                                if (path[1] != ':' && path[0] != '%')
                                {
                                    path = drive.Name.TrimEnd('\\') + path;
                                }

                                if (possibleLocation.IndexOf("%ENV%") >= 0)
                                {
                                    foreach (string dir in dirs)
                                    {
                                        string envPath          = path.Replace("%ENV%", dir);
                                        CompilerInstallInfo inf = GetLocalDMDInstallation(envPath, ref v1, ref v2);
                                        if (inf != null)
                                        {
                                            localDMDInstallations.Add(inf);
                                        }
                                    }
                                }
                                else
                                {
                                    GetLocalDMDInstallation(path, ref v1, ref v2);
                                    CompilerInstallInfo inf = GetLocalDMDInstallation(path, ref v1, ref v2);
                                    if (inf != null)
                                    {
                                        localDMDInstallations.Add(inf);
                                    }
                                }
                            }
                        }
                    }


                    StringBuilder sb = new StringBuilder();
                    foreach (CompilerInstallInfo cii in localDMDInstallations)
                    {
                        sb.Append(cii.ToString()).Append("\r\n");
                    }
                    File.WriteAllText(DataFile.FullName, sb.ToString());
                    //File.WriteAllText(@"C:\Users\Justin\Desktop\LocalInit_" + DateTime.Now.Ticks + ".txt", DateTime.Now.ToLongDateString());
                }
            }
        }