private void Create(UnityProjectState state)
		{
			assetDatabase = state.AssetDatabase;
			BaseDirectory = state.BaseDirectory;

			RootFolder = new Folder("");
			folders = new Dictionary<string, Folder> {{RootFolder.RelativePath, RootFolder}};

			// Build folder structure from files
			foreach (var file in assetDatabase.Files)
				AddFile(file);

			// Build folder structure from empty folders
			foreach (var emptyDirectory in assetDatabase.EmptyDirectories)
				AddEmptyDirectory(emptyDirectory);
		}
		public bool Update(UnityProjectState state)
		{
			if (assetDatabase == null || assetDatabase == state.AssetDatabase || BaseDirectory != state.BaseDirectory)
			{
				Create(state);
				return false;
			}

			var oldAssetDatabase = assetDatabase;
			var newAssetDatabase = state.AssetDatabase;

			assetDatabase = state.AssetDatabase;

			if (state.RenameHint != null)
			{
				RenameFileOrDirectory(state.RenameHint.OldPath, state.RenameHint.newPath);
				return true;
			}

			var addFiles = newAssetDatabase.Files.Where(f => !oldAssetDatabase.Files.Contains(f)).ToArray();
			var addEmptyDirectories = newAssetDatabase.EmptyDirectories.Where(f => !oldAssetDatabase.EmptyDirectories.Contains(f)).ToArray();

			var removeFiles = oldAssetDatabase.Files.Where(f => !newAssetDatabase.Files.Contains(f)).ToArray();
			var removeEmptyDirectories = oldAssetDatabase.EmptyDirectories.Where(f => !newAssetDatabase.EmptyDirectories.Contains(f)).ToArray();

			var numChanges = addFiles.Length + addEmptyDirectories.Length + removeFiles.Length + removeEmptyDirectories.Length;

			if (numChanges == 0)
				return true;

			foreach (var file in addFiles)
				AddFile(file);

			foreach (var file in removeFiles)
				RemoveFile(file, addEmptyDirectories);

			foreach (var directory in addEmptyDirectories)
				AddEmptyDirectory(directory);

			foreach (var directory in removeEmptyDirectories)
				RemoveEmptyDirectory(directory, addEmptyDirectories);

			return true;
		}
		public static void Update (UnitySolution s, UnityProjectState update)
		{
			var existingProjects = s.GetAllProjects ();

			var toRemoves = existingProjects.Where (p => update.Islands.All(p2 => p.Name != p2.Name)).ToArray ();
			foreach (var toRemove in toRemoves)
				s.RootFolder.Items.Remove (toRemove);

			foreach (var projectUpdate in update.Islands.Where(i => i.Files.Count > 0))
			{
				var existing = existingProjects.OfType<DotNetAssemblyProject>().SingleOrDefault (p => p.Name == projectUpdate.Name);
				if (existing == null)
					existing = CreateMonoDevelopProjectFromProjectUpdate (s, projectUpdate);

				ProjectUpdater.Update (existing, projectUpdate);
			}

			s.BaseDirectory = update.BaseDirectory;
		}
		public void Refresh(UnityProjectState state)
		{
			bool updated = folderUpdater.Update(state);

			DispatchService.GuiDispatch(() =>
			{
				if (updated)
				{
					// Updated folder structure, refresh tree
					TreeView.RefreshNode(TreeView.GetRootNode());
				}
				else
				{
					// Created a new folder structure, replace old tree
					TreeView.Clear();
					foreach (var child in folderUpdater.RootFolder.Children)
						TreeView.AddChild(child);					
				}

			});
		}
		public void TestSetup()
		{
			_solution = new UnitySolution ();
			_update = new UnityProjectState ();
		}
		void NewProjectState()
		{
			projectState = new UnityProjectState();
		}
		public void Setup()
		{
			folderUpdater = new FolderUpdater();
			projectState = new UnityProjectState();
		}
		static UnityModeAddin()
		{
			UnityProjectState = new UnityProjectState ();
		}