示例#1
0
        private static void ValidateDependencies()
        {
            try
            {
                using (var md5 = MD5.Create())
                {
                    var dependencies = GetDependencyList();
                    var depPath      = dependenciesPath + "/../";
                    foreach (var depName in dependencies)
                    {
                        var dll     = depPath + depName + ".dll";
                        var md5Name = depPath + "checksum_" + depName + ".md5";
                        if (!System.IO.File.Exists(dll) || !System.IO.File.Exists(md5Name))
                        {
                            _mlStatus    = DulyEditor.ML_STATUS.NOT_INSTALLED;
                            mlStatusInit = true;
                            return;
                        }

                        using (var streamDll = System.IO.File.OpenRead(dll))
                        {
                            var bytes    = System.IO.File.ReadAllBytes(md5Name);
                            var dllBytes = md5.ComputeHash(streamDll);
                            if (bytes.SequenceEqual(dllBytes))
                            {
                                continue;
                            }
                            _mlStatus    = DulyEditor.ML_STATUS.NOT_INSTALLED;
                            mlStatusInit = true;
                            return;
                        }
                    }
                }
                _mlStatus    = DulyEditor.ML_STATUS.INSTALLED;
                mlStatusInit = true;
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                _mlStatus    = DulyEditor.ML_STATUS.NOT_INSTALLED;
                mlStatusInit = true;
            }
        }
示例#2
0
        private void CleanDependencies()
        {
            _mlStatus = DulyEditor.ML_STATUS.UNINSTALLING;
            var archivePath = dependenciesPath + "/../Dnai.ML.PluginDependencies.zip";

            if (System.IO.File.Exists(archivePath))
            {
                System.IO.File.Delete(archivePath);
            }
            var dependencies = System.IO.File.ReadAllLines(Constants.PluginsPath + "/dependencies.txt");
            var depPath      = dependenciesPath + "/../";
            int count        = 0;

            bytesToreceive = dependencies.Count();
            foreach (var depName in dependencies)
            {
                bytesReceived = count;
                progress      = (float)count++ / dependencies.Count();
                percentage    = (int)(progress * 100f);
                var md5 = depPath + "checksum_" + depName + ".md5";
                var dll = depPath + depName + ".dll";
                if (System.IO.File.Exists(dll))
                {
                    System.IO.File.Delete(dll);
                }
                if (System.IO.File.Exists(md5))
                {
                    System.IO.File.Delete(md5);
                }
            }
            bytesReceived       = count;
            progress            = 1f;
            percentage          = 100;
            _mlStatus           = DulyEditor.ML_STATUS.NOT_INSTALLED;
            shouldCloseProgress = true;
        }
示例#3
0
        public override void Draw()
        {
            var old = GUI.contentColor;

            if (wc == null)
            {
                wc = new WebClient();
                wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
                wc.DownloadFileCompleted   += Wc_DownloadFileCompleted;
                dependenciesPath            = Application.dataPath;
                mlStatusInit = false;
                Task.Run(() => ValidateDependencies());
            }

            var ct = new GUIContent(texture, "Machine Learning - " + (_mlStatus == DulyEditor.ML_STATUS.INSTALLED ? "Enabled" : "Disabled"));

            GUI.contentColor = mlStatusInit ? _mlStatusColor[(int)_mlStatus] : Color.gray;
            if (GUILayout.Button(ct, GUILayout.Width(50), GUILayout.Height(50)) && mlStatusInit)
            {
                switch (_mlStatus)
                {
                case DulyEditor.ML_STATUS.NOT_INSTALLED:
                    try
                    {
                        wc.DownloadFileAsync(new Uri(Constants.MlUrl), Application.dataPath + "/../Dnai.ML.PluginDependencies.zip");
                        _mlStatus = DulyEditor.ML_STATUS.DOWNLOADING;
                    }
                    catch (Exception e)
                    {
                        _mlStatus           = DulyEditor.ML_STATUS.NOT_INSTALLED;
                        shouldCloseProgress = true;
                        Debug.Log(e.Message);
                    }
                    break;

                case DulyEditor.ML_STATUS.DOWNLOADING:
                    break;

                case DulyEditor.ML_STATUS.INSTALLED:
                    shouldCleanDependencies = true;
                    break;

                case DulyEditor.ML_STATUS.UNINSTALLING:
                    break;

                default:
                    break;
                }
            }

            GUI.contentColor = old;

            if (_mlStatus == DulyEditor.ML_STATUS.DOWNLOADING ||
                _mlStatus == DulyEditor.ML_STATUS.UNINSTALLING)
            {
                DulyEditor.Instance.Repaint();
            }

            if (shouldCloseProgress)
            {
                shouldCloseProgress = false;
                EditorUtility.ClearProgressBar();
            }
            else if (shouldCleanDependencies)
            {
                shouldCleanDependencies = false;
                Task.Run(() => CleanDependencies());
            }
            else
            {
                switch (_mlStatus)
                {
                case DulyEditor.ML_STATUS.NOT_INSTALLED:
                    break;

                case DulyEditor.ML_STATUS.DOWNLOADING:
                    if (EditorUtility.DisplayCancelableProgressBar("Downloading Machine Learning Package",
                                                                   downloadStatus, progress))
                    {
                        downloadStatus = "Cancelling...";
                        wc?.CancelAsync();
                    }
                    else
                    {
                        downloadStatus = $"Downloading content {bytesReceived}/{bytesToreceive}MB ({percentage}%)";
                    }
                    break;

                case DulyEditor.ML_STATUS.INSTALLED:
                    break;

                case DulyEditor.ML_STATUS.UNINSTALLING:
                    EditorUtility.DisplayProgressBar("Uninstalling Machine Learning Package",
                                                     $"Uninstalling content {bytesReceived}/{bytesToreceive} Files ({percentage}%)", progress);
                    break;

                default:
                    break;
                }
            }
        }