private void GetSupportFilesInProject(string message, object callback)
        {
            IEnumerable <string> filesInSearch = FileWatcher.LAST_OPENED_FILES.ToArray().Reverse();
            var fileCachePath = PathManager.GetGoToFileCachePath();

            if (File.Exists(fileCachePath))
            {
                filesInSearch = filesInSearch.Concat(File.ReadAllLines(fileCachePath));
            }
            else
            {
                filesInSearch = filesInSearch.Concat(FileWatcher.ALLOWED_FILES_CACHE);
            }

            // remove duplicate lines
            HashSet <string> uniqueFilesSet = new HashSet <string>();

            foreach (var item in filesInSearch)
            {
                uniqueFilesSet.Add(Path.GetFullPath(item));
            }

            var files = uniqueFilesSet
                        .Where(f => File.Exists(f))
                        .Select(f => string.Format("\"{0}\"", Utility.PathNormalized(f)));
            var filesInJson = string.Format("[{0}]", String.Join(",", files.ToArray()));

            wrap = new CallbackWrapper(callback);
            wrap.Send(filesInJson);
        }
        private void CheckIfNeedsShowSaveDialog(string modelPath, object callback)
        {
            var  allMainWindowInstaces = MainWindow.GetAllInstances();
            bool inOtherWindows        = false;

            foreach (var window in allMainWindowInstaces)
            {
                if (this.id == window.id)
                {
                    continue;
                }

                var lcoalSettingsFile = LocalSettings.GetLocalSettingFileById(window.id);
                if (File.Exists(lcoalSettingsFile))
                {
                    var content = File.ReadAllText(lcoalSettingsFile);

                    #if UNITY_EDITOR_WIN
                    modelPath = modelPath.Replace("\\", "\\\\");
                    #endif

                    if (content.Contains(modelPath))
                    {
                        inOtherWindows = true;
                        break;
                    }
                }
            }

            wrap = new CallbackWrapper(callback);
            wrap.Send(inOtherWindows ? "no" : "yes");
        }
        private void GetSearchFolder(string message, object callback)
        {
            string folder = new FileInfo(EditorApplication.applicationPath).Directory.FullName;

            folder = Utility.PathNormalized(Utility.PathCombine(folder, "Unity.app", "Contents", "CGIncludes"));
            wrap   = new CallbackWrapper(callback);
            wrap.Send(folder);
        }
        private void FilterNotExistFiles(string message, object callback)
        {
            var files = message.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            files = files.Where(f => File.Exists(f)).Select(f => string.Format("\"{0}\"", Utility.PathNormalized(f))).ToArray();
            var filesInJson = string.Format("[{0}]", String.Join(",", files.ToArray()));

            wrap = new CallbackWrapper(callback);
            wrap.Send(filesInJson);
        }
        private void GetOrCreateConfigPathInternal(string message, object callback, string path, string defaultJsonValue)
        {
            if (!File.Exists(path))
            {
                File.WriteAllText(path, defaultJsonValue);
            }

            wrap = new CallbackWrapper(callback);
            wrap.Send(Utility.PathNormalized(path));
        }
        private void GetEditorPerfsValue(string message, object callback)
        {
            var value = EditorPrefs.GetString(message);

            if (string.IsNullOrEmpty(value))
            {
                value = string.Empty;
            }

            wrap = new CallbackWrapper(callback);
            wrap.Send(value);
        }
        private void GetUserSnippetsFilePath(string lagnuage, object callback)
        {
            var file = PathManager.GetUserSnippetsFilePath(lagnuage);

            if (!File.Exists(file))
            {
                file = "";
            }

            wrap = new CallbackWrapper(callback);
            wrap.Send(file);
        }
        private void GetModelStateStore(string msg, object callback)
        {
            Utility.Log(string.Format("Editor {0} execute GetModelStateStore()", this.id));
            var storeFilePath = PathManager.GetModelStatesStorePath();

            if (!File.Exists(storeFilePath))
            {
                storeFilePath = "";
            }

            wrap = new CallbackWrapper(callback);
            wrap.Send(storeFilePath);
        }
        private void RunCustomizeOpenAction(string id, object callback)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            var entries = UCommandController.GetQuickOpenEntries(id);

            wrap = new CallbackWrapper(callback);
            var json = string.Format("[{0}]", string.Join(",", entries.Select(e => e.ToJsonString()).ToArray()));

            wrap.Send(json);
        }
        private void GetSettingsFileImported(string message, object callback)
        {
            wrap = new CallbackWrapper(callback);
            var path = EditorUtility.OpenFilePanel("Import Settings", Application.dataPath, Constants.SETTING_FILE_EXT);

            if (string.IsNullOrEmpty(path))
            {
                wrap.Send(string.Empty);
            }
            else
            {
                wrap.Send(Path.GetFullPath(Utility.PathNormalized(path)));
            }
        }
        private void LoadAllModels(string message, object callback)
        {
            var guids = AssetDatabase.FindAssets("t:Script");

            var filesInSearch = new List <string>();

            foreach (var id in guids)
            {
                var path = Path.GetFullPath(AssetDatabase.GUIDToAssetPath(id));
                filesInSearch.Add(path);
            }

            var files       = filesInSearch.Select(f => string.Format("\"{0}\"", Utility.PathNormalized(f)));
            var filesInJson = string.Format("[{0}]", String.Join(",", files.ToArray()));

            wrap = new CallbackWrapper(callback);
            wrap.Send(filesInJson);
        }
        private void GetCurrentNeedToBeOpenFile(string message, object callback)
        {
            var path = PlayerPrefs.GetString(Constants.CURRENT_FILE_KEY);

            if (string.IsNullOrEmpty(path))
            {
                path = "";
            }
            else
            {
                // Check if the path exists or not, return empty if it's not exist
                if (path.Contains(":"))
                {
                    // If path with line parameters
                    var temp = path.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    if (temp.Length > 1)
                    {
                        #if UNITY_EDITOR_WIN
                        path = String.Format("{0}:{1}", temp[0], temp[1]);
                        if (!File.Exists(path))
                        #else
                        if (!File.Exists(temp[0]))
                        #endif
                        {
                            path = "";
                        }
                    }
                }
                else
                {
                    if (!File.Exists(path))
                    {
                        path = "";
                    }
                }
            }

            wrap = new CallbackWrapper(callback);
            wrap.Send(Utility.PathNormalized(path));

            PlayerPrefs.DeleteKey(Constants.CURRENT_FILE_KEY);
        }
        private void GetFileModifyTime(string message, object callback)
        {
            wrap = new CallbackWrapper(callback);

            if (string.IsNullOrEmpty(message))
            {
                wrap.Send("-1");
            }
            else
            {
                if (File.Exists(message))
                {
                    wrap.Send(File.GetLastWriteTime(message).ToString("yyyy-MM-dd HH:mm:ss.fff"));
                }
                else
                {
                    wrap.Send("-1");
                }
            }
        }
        private void GetChangesOfModelSinceLastSave(string modelPath, object callback)
        {
            wrap = new CallbackWrapper(callback);

            if (!string.IsNullOrEmpty(modelPath))
            {
                var overviewFile = PathManager.GetModelTempCacheOverviewFilePath(modelPath);
                if (File.Exists(overviewFile))
                {
                    wrap.Send(File.ReadAllText(overviewFile));
                }
                else
                {
                    wrap.Send("");
                }
            }
            else
            {
                wrap.Send("");
            }
        }
        private void GetThemes(string message, object callback)
        {
            var assetsGuid = AssetDatabase.FindAssets("t:TextAsset");
            var jsonFiles  = new List <string>();

            foreach (var item in assetsGuid)
            {
                var path = AssetDatabase.GUIDToAssetPath(item);
                if (path.Contains("uCodeEditor") &&
                    !Path.GetFileName(path).ToLower().Equals("package.json") &&
                    path.ToLower().EndsWith(".json"))
                {
                    jsonFiles.Add(Path.GetFullPath(path));
                }
            }

            // Try get in packages
            //
            var packagePath = Path.Combine(PathManager.GetUCEFolderInProject(), "Themes");

            if (Directory.Exists(packagePath))
            {
                foreach (var path in Directory.GetFiles(packagePath))
                {
                    if (!Path.GetFileName(path).ToLower().Equals("package.json") &&
                        path.ToLower().EndsWith(".json"))
                    {
                        jsonFiles.Add(Path.GetFullPath(path));
                    }
                }
            }

            wrap = new CallbackWrapper(callback);
            var files = jsonFiles.Where(f => File.Exists(f)).Select(f => string.Format("\"{0}\"", Utility.PathNormalized(f))).ToArray();
            var json  = string.Format("[{0}]", String.Join(",", files.ToArray()));

            wrap.Send(json);
        }
        private void SaveInternal(string message, object callback, bool forceRefresh = false, bool forceNoRefresh = false)
        {
            Utility.Log(string.Format("Editor {0} save action", this.id));

            wrap = new CallbackWrapper(callback);

            try
            {
                string data  = Utility.FromBase64(message);
                int    index = data.IndexOf("?");
                if (index == -1)
                {
                    return;
                }

                string filePath = data.Substring(0, index);
                string content  = data.Substring(index + 1);

                if (!string.IsNullOrEmpty(filePath))
                {
                    bool isInMomery = filePath.StartsWith("inmemory");
                    bool isSaveTo   = filePath.StartsWith("_saveto_");

                    // if the file is not saved
                    if (isInMomery || isSaveTo)
                    {
                        var fileName = filePath.Substring(9);
                        filePath = EditorUtility.SaveFilePanel("Save To", Application.dataPath, fileName, "");
                    }

                    if (!string.IsNullOrEmpty(filePath))
                    {
                        filePath = Path.GetFullPath(filePath);
                        Encoding utf8withtouBom = new UTF8Encoding(false);
                        File.WriteAllText(filePath, content, utf8withtouBom);
                        wrap.Send(filePath);

                        if (forceNoRefresh)
                        {
                            this.ClearChangesOverviewCache(filePath);
                            return;
                        }

                        // Don't reimport cs script here, beacause it will
                        // casue scripts compile action and Unity Editor UI
                        // may freezed.
                        bool isInProject          = filePath.IndexOf(Application.dataPath) != -1;
                        bool isCSScript           = Utility.IsCSharpScript(filePath);
                        bool matchImportCondition = isInProject && (forceRefresh || isInMomery || !isCSScript);
                        if (matchImportCondition)
                        {
                            var assetPath = ToProjectRelativePath(filePath);
                            AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.Default);
                        }

                        this.ClearChangesOverviewCache(filePath);
                    }
                }
                else
                {
                    Debug.LogError("No file saved");
                    wrap.Send("failed");
                }
            }
            catch (Exception e)
            {
                wrap.Send("failed");
                Debug.LogError(e);
            }
        }
 private void LoadLocalSettings(string message, object callback)
 {
     wrap = new CallbackWrapper(callback);
     wrap.Send(Utility.PathNormalized(LocalSettings.GetLocalSettingsPath(this.id)));
 }
 private void GetPackagesFolderPath(string message, object callback)
 {
     wrap = new CallbackWrapper(callback);
     wrap.Send(PathManager.GetUnityPackagesFolder());
 }
 private void GetProjectId(string message, object callback)
 {
     wrap = new CallbackWrapper(callback);
     wrap.Send(OnLoad.Id);
 }
 private void GetQuickOpenActions(string message, object callback)
 {
     wrap = new CallbackWrapper(callback);
     wrap.Send(UCommandController.GetAllQuickOpenCommandsJson());
 }