Exemplo n.º 1
0
        void Init()
        {
            string currentLocation = IsInstalled ? MmpPath : null;

            IsInstalled = false;
            versions    = null;

            FrameworkDirectory = "/Library/Frameworks/Xamarin.Mac.framework/Versions/Current";
            var envFrameworkDir = Environment.GetEnvironmentVariable("XAMMAC_FRAMEWORK_PATH");

            if (envFrameworkDir != null && Directory.Exists(envFrameworkDir))
            {
                FrameworkDirectory = envFrameworkDir;
            }

            var versionPath = Path.Combine(FrameworkDirectory, "Version");

            if (File.Exists(versionPath))
            {
                Version = ReadVersion(versionPath);
                lastWriteTimes [versionPath] = File.GetLastWriteTimeUtc(versionPath);

                var path = Path.Combine(FrameworkDirectory, "Versions.plist");
                if (File.Exists(path))
                {
                    try {
                        versions = PDictionary.FromFile(path);
                    } catch {
                        LoggingService.LogWarning("Xamarin.Mac installation is corrupt: invalid Versions.plist at {0}.", path);
                    }
                }

                if (versions == null)
                {
                    versions = CreateDefaultVersionsPlist(Version);
                }
            }
            else
            {
                NotInstalled(versionPath, error: false);
                AnalyticsService.ReportSdkVersion("XS.Core.SDK.Mac.Version", string.Empty);
                return;
            }

            var paths = Version >= new MacOSXSdkVersion(1, 9, 0)
                                ? Detect2x()
                                : Detect1x();

            foreach (var path in paths)
            {
                if (!File.Exists(path))
                {
                    NotInstalled(path);
                    return;
                }

                lastWriteTimes [path] = File.GetLastWriteTimeUtc(path);
            }

            IsInstalled = true;
            LoggingService.LogInfo("Found Xamarin.Mac, version {0}.", Version);
            AnalyticsService.ReportSdkVersion("XS.Core.SDK.Mac.Version", Version.ToString());

            if (Changed != null && currentLocation != MmpPath)
            {
                Changed(this, EventArgs.Empty);
            }
        }
Exemplo n.º 2
0
        void Init()
        {
            string currentLocation = IsInstalled ? Path.Combine(BinDir, "mtouch") : null;

            IsInstalled = false;
            versions    = null;

            if (string.IsNullOrEmpty(SdkDir))
            {
                foreach (var loc in DefaultLocations)
                {
                    if (IsInstalled = ValidateSdkLocation(loc, out hasUsrSubdir))
                    {
                        SdkDir = loc;
                        break;
                    }
                }
            }
            else
            {
                IsInstalled = ValidateSdkLocation(SdkDir, out hasUsrSubdir);
            }

            string mtouch = null;

            if (IsInstalled)
            {
                mtouch         = Path.Combine(BinDir, "mtouch");
                lastMTExeWrite = File.GetLastWriteTimeUtc(mtouch);
                Version        = ReadVersion();

                if (Version.CompareTo(requiredXI) >= 0)
                {
                    LoggingService.LogInfo("Found Xamarin.iOS, version {0}.", Version);

                    var path = Path.Combine(SdkDir, "Versions.plist");
                    if (File.Exists(path))
                    {
                        try {
                            versions = PDictionary.FromFile(path);
                        } catch {
                            LoggingService.LogWarning("Xamarin.iOS installation is corrupt: invalid Versions.plist at {0}.", path);
                        }
                    }

                    if (versions == null)
                    {
                        versions = CreateDefaultVersionsPlist();
                    }
                }
                else
                {
                    SdkNotInstalledReason = string.Format("Found unsupported Xamarin.iOS, version {0}.\nYou need Xamarin.iOS {1} or above.", Version, requiredXI.ToString());
                    LoggingService.LogWarning(SdkNotInstalledReason);
                    Version     = new IPhoneSdkVersion();
                    versions    = new PDictionary();
                    IsInstalled = false;
                }

                AnalyticsService.ReportSdkVersion("XS.Core.SDK.iOS.Version", Version.ToString());
            }
            else
            {
                lastMTExeWrite = DateTime.MinValue;
                Version        = new IPhoneSdkVersion();
                versions       = new PDictionary();

                SdkNotInstalledReason = string.Format("Xamarin.iOS not installed.\nCan't find mtouch or the Version file at {0}.", SdkDir);
                LoggingService.LogInfo(SdkNotInstalledReason);

                AnalyticsService.ReportSdkVersion("XS.Core.SDK.iOS.Version", string.Empty);
            }

            if (Changed != null && currentLocation != mtouch)
            {
                Changed(this, EventArgs.Empty);
            }
        }
Exemplo n.º 3
0
        static void Init()
        {
            string devroot = null, vplist = null, xcode = null;
            bool   foundSdk = false;

            SetInvalid();

            DeveloperRoot = Environment.GetEnvironmentVariable("MD_APPLE_SDK_ROOT");
            if (string.IsNullOrEmpty(DeveloperRoot))
            {
                DeveloperRoot = GetConfiguredSdkLocation();

                if (string.IsNullOrEmpty(DeveloperRoot) && File.Exists("/usr/bin/xcode-select"))
                {
                    var startInfo = new ProcessStartInfo("/usr/bin/xcode-select", "--print-path");
                    startInfo.RedirectStandardOutput = true;
                    startInfo.UseShellExecute        = false;

                    var process = new Process();
                    var stdout  = string.Empty;

                    try {
                        process.StartInfo           = startInfo;
                        process.OutputDataReceived += (sender, e) => stdout += e.Data;
                        process.Start();
                        process.WaitForExit();
                    } catch (Win32Exception) {
                        stdout = string.Empty;
                    }

                    stdout = stdout.Trim();

                    if (!string.IsNullOrEmpty(stdout) && Directory.Exists(stdout))
                    {
                        if (stdout.EndsWith("/Contents/Developer", StringComparison.Ordinal))
                        {
                            stdout = stdout.Substring(0, stdout.Length - "/Contents/Developer".Length);
                        }

                        DeveloperRoot = stdout;
                    }
                }
            }

            if (string.IsNullOrEmpty(DeveloperRoot))
            {
                foreach (var v in DefaultRoots)
                {
                    if (ValidateSdkLocation(v, out xcode, out vplist, out devroot))
                    {
                        foundSdk = true;
                        break;
                    }

                    LoggingService.LogInfo("A valid Xcode installation was not found at '{0}'", v);
                }
            }
            else if (!ValidateSdkLocation(DeveloperRoot, out xcode, out vplist, out devroot))
            {
                LoggingService.LogError("A valid Xcode installation was not found at the configured location: '{0}'", DeveloperRoot);
                SetInvalid();
                return;
            }
            else
            {
                foundSdk = true;
            }

            if (foundSdk)
            {
                XcodePath                 = xcode;
                DeveloperRoot             = devroot;
                DeveloperRootVersionPlist = vplist;
                Environment.SetEnvironmentVariable("XCODE_DEVELOPER_DIR_PATH", DeveloperRoot);
            }
            else
            {
                SetInvalid();
                return;
            }

            try {
                var plist = Path.Combine(XcodePath, "Contents", "Info.plist");

                if (!File.Exists(plist))
                {
                    SetInvalid();
                    return;
                }

                lastWritten = File.GetLastWriteTime(plist);

                XcodeVersion  = new Version(3, 2, 6);
                XcodeRevision = "0";

                // DTXCode was introduced after xcode 3.2.6 so it may not exist
                var dict = PDictionary.FromFile(plist);

                PString value;
                if (dict.TryGetValue("DTXcode", out value))
                {
                    DTXcode = value.Value;
                }

                if (dict.TryGetValue("CFBundleShortVersionString", out value))
                {
                    XcodeVersion = Version.Parse(value.Value);
                }

                if (dict.TryGetValue("CFBundleVersion", out value))
                {
                    XcodeRevision = value.Value;
                }

                LoggingService.LogInfo("Found Xcode, version {0} ({1}).", XcodeVersion, XcodeRevision);
                AnalyticsService.ReportContextProperty("XS.Core.SDK.Xcode.Version", XcodeVersion.ToString());
                IsValid = true;
            } catch (Exception ex) {
                LoggingService.LogError("Error loading Xcode information for prefix '" + DeveloperRoot + "'", ex);
                SetInvalid();
            }
        }