Ejemplo n.º 1
0
        static PropertyService()
        {
            Counters.PropertyServiceInitialization.BeginTiming();

            IsWindows = Path.DirectorySeparatorChar == '\\';
            IsMac     = !IsWindows && IsRunningOnMac();

            FilePath testProfileRoot = Environment.GetEnvironmentVariable("MONODEVELOP_PROFILE");

            if (!testProfileRoot.IsNullOrEmpty)
            {
                Locations = UserDataLocations.ForTest(CURRENT_PROFILE_VERSION, testProfileRoot);
            }
            else
            {
                Locations = GetLocations(CURRENT_PROFILE_VERSION);
            }

            string            migrateVersion    = null;
            UserDataLocations migratableProfile = null;

            var prefsPath = Locations.Config.Combine(FileName);

            if (!File.Exists(prefsPath))
            {
                if (GetMigratableProfile(testProfileRoot, out migratableProfile, out migrateVersion))
                {
                    FilePath migratePrefsPath = migratableProfile.Config.Combine(FileName);
                    try {
                        var parentDir = prefsPath.ParentDirectory;
                        //can't use file service until property sevice in initialized
                        if (!Directory.Exists(parentDir))
                        {
                            Directory.CreateDirectory(parentDir);
                        }
                        File.Copy(migratePrefsPath, prefsPath);
                        LoggingService.LogInfo("Migrated core properties from {0}", migratePrefsPath);
                    } catch (IOException ex) {
                        string message = string.Format("Failed to migrate core properties from {0}", migratePrefsPath);
                        LoggingService.LogError(message, ex);
                    }
                }
                else
                {
                    LoggingService.LogInfo("Did not find previous version from which to migrate data");
                }
            }

            if (!LoadProperties(prefsPath))
            {
                properties = new Properties();
                properties.Set("MonoDevelop.Core.FirstRun", true);
            }

            if (migratableProfile != null)
            {
                UserDataMigrationService.SetMigrationSource(migratableProfile, migrateVersion);
            }

            properties.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args) {
                if (PropertyChanged != null)
                {
                    PropertyChanged(sender, args);
                }
            };

            Counters.PropertyServiceInitialization.EndTiming();
        }
Ejemplo n.º 2
0
        static void HandleUserDataMigration(object sender, ExtensionNodeEventArgs args)
        {
            if (args.Change != ExtensionChange.Add)
            {
                return;
            }

            var node = (UserDataMigrationNode)args.ExtensionNode;

            if (!CheckVersion(node, version))
            {
                return;
            }

            FilePath source = FilePath.Null;
            FilePath target = FilePath.Null;

            try {
                source = profile.GetLocation(node.SourceKind).Combine(node.SourcePath);
                target = UserProfile.Current.GetLocation(node.TargetKind).Combine(node.TargetPath);

                bool sourceIsDirectory = Directory.Exists(source);

                if (sourceIsDirectory)
                {
                    if (Directory.Exists(target))
                    {
                        return;
                    }
                }
                else
                {
                    if (File.Exists(target) || Directory.Exists(target) || !File.Exists(source))
                    {
                        return;
                    }
                }

                LoggingService.LogInfo("Migrating '{0}' to '{1}'", source, target);
                if (!sourceIsDirectory)
                {
                    FileService.EnsureDirectoryExists(target.ParentDirectory);
                }

                var handler = node.GetHandler();
                if (handler != null)
                {
                    handler.Migrate(source, target);
                    return;
                }

                if (sourceIsDirectory)
                {
                    DirectoryCopy(source, target);
                }
                else
                {
                    File.Copy(source, target);
                }
            } catch (Exception ex) {
                string message = string.Format("{0}: Failed to migrate '{1}' to '{2}'",
                                               node.Addin.Id, source.ToString() ?? "", target.ToString() ?? "");
                LoggingService.LogError(message, ex);
            }
        }