Example #1
0
 public bool Close()
 {
     if (Current != this)
     {
         throw new InvalidOperationException();
     }
     if (Current == Null)
     {
         return(true);
     }
     fsWatcher?.Dispose();
     fsWatcher = null;
     UserPreferences.Documents.Clear();
     foreach (var doc in documents.ToList())
     {
         UserPreferences.Documents.Add(doc.Path);
         if (!CloseDocument(doc))
         {
             return(false);
         }
     }
     try {
         TangerineYuzu.Instance.Value.WriteObjectToFile(UserprefsPath, UserPreferences, Serialization.Format.JSON);
     } catch (System.Exception) { }
     AssetBundle.Current = null;
     Current             = Null;
     return(true);
 }
Example #2
0
        public bool Close()
        {
            if (Current != this)
            {
                throw new InvalidOperationException();
            }
            if (Current == Null)
            {
                return(true);
            }
            fsWatcher?.Dispose();
            fsWatcher = null;
            var userprefs = new Userprefs();

            if (Document.Current != null)
            {
                userprefs.CurrentDocument = Document.Current.Path;
            }
            foreach (var doc in documents.ToList())
            {
                if (!CloseDocument(doc))
                {
                    return(false);
                }
                userprefs.Documents.Add(doc.Path);
            }
            try {
                Serialization.WriteObjectToFile(UserprefsPath, userprefs, Serialization.Format.JSON);
            } catch (System.Exception) { }
            AssetBundle.Current = null;
            Current             = Null;
            return(true);
        }
Example #3
0
        public bool Close()
        {
            if (Current != this)
            {
                throw new InvalidOperationException();
            }
            if (Current == Null)
            {
                return(true);
            }
            if (PluginLoader.CurrentPlugin != null)
            {
                foreach (var action in PluginLoader.CurrentPlugin.TangerineProjectClosing)
                {
                    action?.Invoke();
                }
            }
            var modifiedDocuments = documents.Where(d => d.IsModified).ToList();

            foreach (var d in modifiedDocuments)
            {
                // Call Document.Close() instead of CloseDocument, since latter invokes Document.SetCurrent() and forces document loading.
                // All this stuff for the sake of performance.
                if (!d.Close())
                {
                    return(false);
                }
            }
            UserPreferences.Documents.Clear();
            foreach (var d in documents)
            {
                UserPreferences.Documents.Add(d.Path);
            }
            foreach (var d in modifiedDocuments)
            {
                CloseDocument(d, true);
            }
            var closingDocuments = documents.ToList();

            Document.SetCurrent(null);
            documents.Clear();
            foreach (var doc in closingDocuments)
            {
                if (!CloseDocument(doc))
                {
                    return(false);
                }
            }
            try {
                TangerinePersistence.Instance.WriteObjectToFile(UserprefsPath, UserPreferences, Persistence.Format.Json);
            } catch (System.Exception) { }
            AssetBundle.Current = null;
            FileSystemWatcher?.Dispose();
            FileSystemWatcher = null;
            Current           = Null;
            return(true);
        }
Example #4
0
        private void InvalidateFSWatcher(string path)
        {
            fsWatcher?.Dispose();
            fsWatcher = new Lime.FileSystemWatcher(path, includeSubdirectories: false);
            // TODO: throttle
            Action OnFsWatcherChanged = () => {
                InvalidateView(model.CurrentPath);
            };

            fsWatcher.Deleted += (p) => {
                selection.Deselect(p);
                OnFsWatcherChanged();
            };
            fsWatcher.Created += (p) => OnFsWatcherChanged();
            fsWatcher.Renamed += (p) => OnFsWatcherChanged();
        }
Example #5
0
        public void Open()
        {
            if (Current != Null)
            {
                throw new InvalidOperationException();
            }
            Current             = this;
            AssetBundle.Current = new UnpackedAssetBundle(AssetsDirectory);
            if (File.Exists(UserprefsPath))
            {
                try {
                    var userprefs = Serialization.ReadObjectFromFile <Userprefs>(UserprefsPath);
                    foreach (var path in userprefs.Documents)
                    {
                        try {
                            OpenDocument(path);
                        } catch (System.Exception e) {
                            Debug.Write($"Failed to open document '{path}': {e.Message}");
                        }
                    }
                    var currentDoc = documents.FirstOrDefault(d => d.Path == userprefs.CurrentDocument) ?? documents.FirstOrDefault();
                    Document.SetCurrent(currentDoc);
                } catch (System.Exception e) {
                    Debug.Write($"Failed to load the project user preferences: {e}");
                }
            }
            fsWatcher          = new Lime.FileSystemWatcher(AssetsDirectory, includeSubdirectories: true);
            fsWatcher.Changed += HandleFileSystemWatcherEvent;
            fsWatcher.Created += HandleFileSystemWatcherEvent;
            fsWatcher.Deleted += HandleFileSystemWatcherEvent;
            fsWatcher.Renamed += HandleFileSystemWatcherEvent;
            var files = Directory.EnumerateFiles(Path.Combine(Project.Current.AssetsDirectory, "Overlays"))
                        .Where(file => Path.GetExtension(file) == ".tan" || Path.GetExtension(file) == ".scene");

            foreach (var file in files)
            {
                Project.Current.Overlays.Add(Path.GetFileNameWithoutExtension(file), new Frame(file));
            }
        }
Example #6
0
        public void Open()
        {
            Opening?.Invoke(CitprojPath);
            if (Current != Null)
            {
                throw new InvalidOperationException();
            }
            Current = this;
            TangerineAssetBundle tangerineAssetBundle = new TangerineAssetBundle(AssetsDirectory);

            if (!tangerineAssetBundle.IsActual())
            {
                tangerineAssetBundle.CleanupBundle();
            }
            AssetBundle.Current = tangerineAssetBundle;
            Preferences         = new ProjectPreferences();
            Preferences.Initialize();
            FileSystemWatcher = new FileSystemWatcher(AssetsDirectory, includeSubdirectories: true);
            if (File.Exists(UserprefsPath))
            {
                try {
                    UserPreferences = TangerinePersistence.Instance.ReadObjectFromFile <ProjectUserPreferences>(UserprefsPath);
                    foreach (var path in UserPreferences.Documents)
                    {
                        try {
                            if (GetFullPath(path, out string fullPath))
                            {
                                OpenDocument(path, delayLoad: true);
                            }
                        } catch (Exception e) {
                            Debug.Write($"Failed to open document '{path}': {e.Message}");
                        }
                    }
                    var currentDoc = documents.FirstOrDefault(d => d.Path == UserPreferences.CurrentDocument) ?? documents.FirstOrDefault();
                    try {
                        Document.SetCurrent(currentDoc);
                    } catch (Exception e) {
                        if (currentDoc != null)
                        {
                            CloseDocument(currentDoc);
                        }
                        throw;
                    }
                } catch (Exception e) {
                    Debug.Write($"Failed to load the project user preferences: {e}");
                }
            }
            SetLocale(Locale);
            FileSystemWatcher.Changed += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Created += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Deleted += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Renamed += (previousPath, path) => {
                // simulating rename as pairs of deleted / created events
                HandleFileSystemWatcherEvent(path);
                if (File.Exists(path))
                {
                    HandleFileSystemWatcherEvent(previousPath);
                    HandleFileSystemWatcherEvent(path);
                }
                else if (Directory.Exists(path))
                {
                    foreach (var f in new ScanOptimizedFileEnumerator(path, null).Enumerate())
                    {
                        HandleFileSystemWatcherEvent(Path.Combine(previousPath, f.Path));
                        HandleFileSystemWatcherEvent(Path.Combine(path, f.Path));
                    }
                }
            };
            var overlaysPath = Path.Combine(Current.AssetsDirectory, "Overlays");

            if (Directory.Exists(overlaysPath))
            {
                var files = Directory.EnumerateFiles(overlaysPath)
                            .Where(file => file.EndsWith(".tan", StringComparison.OrdinalIgnoreCase));
                foreach (var file in files)
                {
                    Current.Overlays.Add(Path.GetFileNameWithoutExtension(file),
                                         (Widget)Node.CreateFromAssetBundle(Path.ChangeExtension(file, null), null, TangerinePersistence.Instance));
                }
            }

            registeredNodeTypes.AddRange(GetNodesTypesOrdered("Lime"));
            registeredComponentTypes.AddRange(GetComponentsTypes("Lime"));
            foreach (var type in PluginLoader.EnumerateTangerineExportedTypes())
            {
                if (typeof(Node).IsAssignableFrom(type))
                {
                    registeredNodeTypes.Add(type);
                }
                else if (typeof(NodeComponent).IsAssignableFrom(type))
                {
                    registeredComponentTypes.Add(type);
                }
            }
            if (PluginLoader.CurrentPlugin != null)
            {
                foreach (var action in PluginLoader.CurrentPlugin.TangerineProjectOpened)
                {
                    action?.Invoke();
                }
            }
        }
Example #7
0
        public Project(string citprojPath)
        {
            if (Current != Null)
            {
                throw new InvalidOperationException();
            }
            Current         = this;
            CitprojPath     = citprojPath;
            UserprefsPath   = Path.ChangeExtension(citprojPath, ".userprefs");
            AssetsDirectory = Path.Combine(Path.GetDirectoryName(CitprojPath), "Data");
            UntitledPath    = Path.Combine(AssetsDirectory, ".untitled");
            if (!Directory.Exists(AssetsDirectory))
            {
                throw new InvalidOperationException($"Assets directory {AssetsDirectory} doesn't exist.");
            }
            var di = Directory.CreateDirectory(UntitledPath);

            di.Attributes |= FileAttributes.Hidden;
            var untitledCookingRulePath = Path.Combine(UntitledPath, "#CookingRules.txt");

            if (!File.Exists(untitledCookingRulePath))
            {
                using (var writer = File.CreateText(untitledCookingRulePath)) {
                    writer.WriteLine("Ignore Yes");
                }
            }
            The.Workspace.Open(citprojPath);
            UpdateTextureParams();

            Opening?.Invoke(CitprojPath);
            Preferences = new ProjectPreferences();
            Preferences.Initialize();
            FileSystemWatcher = new FileSystemWatcher(AssetsDirectory, includeSubdirectories: true);
            if (File.Exists(UserprefsPath))
            {
                try {
                    UserPreferences = TangerinePersistence.Instance.ReadObjectFromFile <ProjectUserPreferences>(UserprefsPath);
                    foreach (var path in UserPreferences.Documents)
                    {
                        try {
                            if (GetFullPath(path, out string fullPath))
                            {
                                OpenDocument(path, delayLoad: true);
                            }
                        } catch (Exception e) {
                            Debug.Write($"Failed to open document '{path}': {e.Message}");
                        }
                    }
                    var currentDoc = documents.FirstOrDefault(d => d.Path == UserPreferences.CurrentDocument) ?? documents.FirstOrDefault();
                    try {
                        Document.SetCurrent(currentDoc);
                    } catch (Exception e) {
                        if (currentDoc != null)
                        {
                            CloseDocument(currentDoc);
                        }
                        throw;
                    }
                } catch (Exception e) {
                    Debug.Write($"Failed to load the project user preferences: {e}");
                }
            }
            SetLocale(Locale);
            FileSystemWatcher.Changed += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Created += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Deleted += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Renamed += (previousPath, path) => {
                // simulating rename as pairs of deleted / created events
                HandleFileSystemWatcherEvent(path);
                if (File.Exists(path))
                {
                    HandleFileSystemWatcherEvent(previousPath);
                    HandleFileSystemWatcherEvent(path);
                }
                else if (Directory.Exists(path))
                {
                    foreach (var f in new ScanOptimizedFileEnumerator(path, null).Enumerate())
                    {
                        HandleFileSystemWatcherEvent(Path.Combine(previousPath, f.Path));
                        HandleFileSystemWatcherEvent(Path.Combine(path, f.Path));
                    }
                }
            };
            if (Directory.Exists(AssetBundle.Current.ToSystemPath("Overlays")))
            {
                foreach (var file in AssetBundle.Current.EnumerateFiles("Overlays", ".tan"))
                {
                    Current.Overlays.Add(Path.GetFileNameWithoutExtension(file),
                                         (Widget)Node.CreateFromAssetBundle(Path.ChangeExtension(file, null), null, TangerinePersistence.Instance));
                }
            }
            registeredNodeTypes.AddRange(GetNodesTypesOrdered("Lime"));
            registeredComponentTypes.AddRange(GetComponentsTypes("Lime"));
            foreach (var type in PluginLoader.EnumerateTangerineExportedTypes())
            {
                if (typeof(Node).IsAssignableFrom(type))
                {
                    registeredNodeTypes.Add(type);
                }
                else if (typeof(NodeComponent).IsAssignableFrom(type))
                {
                    registeredComponentTypes.Add(type);
                }
            }
            if (PluginLoader.CurrentPlugin != null)
            {
                foreach (var action in PluginLoader.CurrentPlugin.TangerineProjectOpened)
                {
                    action?.Invoke();
                }
            }
        }
Example #8
0
        public void Open()
        {
            Opening?.Invoke(CitprojPath);
            if (Current != Null)
            {
                throw new InvalidOperationException();
            }
            Current = this;
            TangerineAssetBundle tangerineAssetBundle;

            AssetBundle.Current = tangerineAssetBundle = new TangerineAssetBundle(AssetsDirectory);
            if (!tangerineAssetBundle.IsActual())
            {
                tangerineAssetBundle.CleanupBundle();
            }
            Preferences = new ProjectPreferences();
            Preferences.Initialize();
            if (File.Exists(UserprefsPath))
            {
                try {
                    UserPreferences = TangerineYuzu.Instance.Value.ReadObjectFromFile <ProjectUserPreferences>(UserprefsPath);
                    foreach (var path in UserPreferences.Documents)
                    {
                        try {
                            OpenDocument(path);
                        } catch (System.Exception e) {
                            Debug.Write($"Failed to open document '{path}': {e.Message}");
                        }
                    }
                    var currentDoc = documents.FirstOrDefault(d => d.Path == UserPreferences.CurrentDocument) ?? documents.FirstOrDefault();
                    Document.SetCurrent(currentDoc);
                } catch (System.Exception e) {
                    Debug.Write($"Failed to load the project user preferences: {e}");
                }
            }
            fsWatcher          = new Lime.FileSystemWatcher(AssetsDirectory, includeSubdirectories: true);
            fsWatcher.Changed += HandleFileSystemWatcherEvent;
            fsWatcher.Created += HandleFileSystemWatcherEvent;
            fsWatcher.Deleted += HandleFileSystemWatcherEvent;
            fsWatcher.Renamed += HandleFileSystemWatcherEvent;
            var overlaysPath = Path.Combine(Project.Current.AssetsDirectory, "Overlays");

            if (Directory.Exists(overlaysPath))
            {
                var files = Directory.EnumerateFiles(overlaysPath)
                            .Where(file => Path.GetExtension(file) == ".tan" || Path.GetExtension(file) == ".scene");
                foreach (var file in files)
                {
                    Project.Current.Overlays.Add(Path.GetFileNameWithoutExtension(file), new Frame(file));
                }
            }

            registeredNodeTypes.AddRange(GetNodesTypesOrdered("Lime"));
            registeredComponentTypes.AddRange(GetComponentsTypes("Lime"));
            foreach (var type in Orange.PluginLoader.EnumerateTangerineExportedTypes())
            {
                if (typeof(Node).IsAssignableFrom(type))
                {
                    registeredNodeTypes.Add(type);
                }
                else if (typeof(NodeComponent).IsAssignableFrom(type))
                {
                    registeredComponentTypes.Add(type);
                }
            }
        }