//TODO: it would be nice to migrate custom addins that are installed after first run //maybe we would maintain a property with IDs of migrated addins, and check that on addin load //and if an unknown addin comes along, re-migrate just nodes of that addin public static void SetMigrationSource (UserDataLocations profile, string version) { if (UserDataMigrationService.profile != null) throw new InvalidOperationException ("Already set"); if (profile == null) throw new ArgumentNullException ("profile"); if (version == null) throw new ArgumentNullException ("version"); UserDataMigrationService.profile = profile; UserDataMigrationService.version = version; }
static UserDataLocations GetLocations(string profileVersion) { if (IsWindows) { return(UserDataLocations.ForWindows(profileVersion)); } else if (IsMac) { return(UserDataLocations.ForMac(profileVersion)); } else { return(UserDataLocations.ForUnix(profileVersion)); } }
static bool GetMigratableProfile(FilePath testProfileRoot, out UserDataLocations profile, out string version) { profile = null; version = null; //TODO: check 2.6 when 2.8 is released, etc string[] migratableVersions = { }; //test profiles only migrate from test profiles if (!testProfileRoot.IsNullOrEmpty) { for (int i = migratableVersions.Length - 1; i >= 0; i--) { var p = UserDataLocations.ForTest(migratableVersions[i], testProfileRoot); if (File.Exists(p.Config.Combine(FileName))) { profile = p; version = migratableVersions[i]; return(true); } } return(false); } //try versioned profiles for (int i = migratableVersions.Length - 1; i >= 0; i--) { var p = UserDataLocations.ForTest(migratableVersions[i], testProfileRoot); if (File.Exists(p.Config.Combine(FileName))) { profile = p; version = migratableVersions[i]; return(true); } } //try the old unversioned MD <= 2.4 profile var md24 = UserDataLocations.ForMD24(); if (File.Exists(md24.Config.Combine(FileName))) { profile = md24; version = "2.4"; return(true); } return(false); }
//TODO: it would be nice to migrate custom addins that are installed after first run //maybe we would maintain a property with IDs of migrated addins, and check that on addin load //and if an unknown addin comes along, re-migrate just nodes of that addin public static void SetMigrationSource(UserDataLocations profile, string version) { if (UserDataMigrationService.profile != null) { throw new InvalidOperationException("Already set"); } if (profile == null) { throw new ArgumentNullException("profile"); } if (version == null) { throw new ArgumentNullException("version"); } UserDataMigrationService.profile = profile; UserDataMigrationService.version = version; }
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(); }