bool CheckPackmanOperation(long operationId, PackmanOperationType operationType)
        {
            NativeStatusCode statusCode = NativeClient.GetOperationStatus(operationId);

            if (statusCode == NativeStatusCode.NotFound)
            {
                Debug.LogError("OperationID " + operationId + " Not Found");
                return(true);
            }
            else if (statusCode == NativeStatusCode.Error)
            {
                Error error = NativeClient.GetOperationError(operationId);
                Debug.LogError("OperationID " + operationId + " failed with Error: " + error);
                return(true);
            }
            else if (statusCode == NativeStatusCode.InProgress || statusCode == NativeStatusCode.InQueue)
            {
                return(false);
            }
            else if (statusCode == NativeStatusCode.Done)
            {
                System.Console.WriteLine("OperationID " + operationId + " Done");
                switch (operationType)
                {
                case PackmanOperationType.List:
                    ExtractCurrentXiaomiPackageInfo(operationId);
                    break;

                case PackmanOperationType.Add:
                    currentXiaomiPackageVersion = latestXiaomiPackageVersion;
                    xiaomiPackageInstalled      = true;
                    break;

                case PackmanOperationType.Remove:
                    currentXiaomiPackageVersion = "";
                    xiaomiPackageInstalled      = false;
                    break;

                case PackmanOperationType.Search:
                    ExtractLatestXiaomiPackageInfo(operationId);
                    break;

                default:
                    System.Console.WriteLine("Type " + operationType + " Not Supported");
                    break;
                }
                return(true);
            }

            return(true);
        }
Exemplo n.º 2
0
 public RequestQueueItem(Request r, PackmanOperationType type)
 {
     Request       = r;
     OperationType = type;
 }
        private void XiaomiPackageControlGUI()
        {
            EditorGUI.BeginDisabledGroup(!isVersionInitialized || packmanOperationRunning);

            if (!xiaomiPackageInstalled)
            {
                if (GUILayout.Button("Add", GUILayout.Width(60)))
                {
                    if (packmanOperationRunning)
                    {
                        return;
                    }

                    NativeStatusCode code = NativeClient.Add(out packmanOperationId, LatestXiaomiPackageId);
                    if (code == NativeStatusCode.Error)
                    {
                        Debug.LogError("Add " + LatestXiaomiPackageId + " error, please add it again.");
                        return;
                    }
                    packmanOperationType = PackmanOperationType.Add;
                    System.Console.WriteLine("Add: OperationID " + packmanOperationId + " for " + LatestXiaomiPackageId);
                    packmanOperationRunning = true;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                if (!string.IsNullOrEmpty(latestXiaomiPackageVersion) && currentXiaomiPackageVersion != latestXiaomiPackageVersion)
                {
                    if (GUILayout.Button("Update", GUILayout.Width(60)))
                    {
                        if (packmanOperationRunning)
                        {
                            return;
                        }

                        if (EditorUtility.DisplayDialog("Update Xiaomi SDK", "Are you sure you want to update to " + latestXiaomiPackageVersion + " ?", "Yes", "No"))
                        {
                            NativeStatusCode code = NativeClient.Add(out packmanOperationId, LatestXiaomiPackageId);
                            if (code == NativeStatusCode.Error)
                            {
                                Debug.LogError("Update " + LatestXiaomiPackageId + " error, please update it again.");
                                return;
                            }
                            packmanOperationType = PackmanOperationType.Add;
                            System.Console.WriteLine("Update: OperationID " + packmanOperationId + " for " + LatestXiaomiPackageId);
                            packmanOperationRunning = true;
                        }
                    }
                }
                if (GUILayout.Button("Remove", GUILayout.Width(60)))
                {
                    if (packmanOperationRunning)
                    {
                        return;
                    }

                    NativeStatusCode code = NativeClient.Remove(out packmanOperationId, CurrentXiaomiPackageId);
                    if (code == NativeStatusCode.Error)
                    {
                        Debug.LogError("Remove " + CurrentXiaomiPackageId + " error, please remove it again.");
                        return;
                    }
                    packmanOperationType = PackmanOperationType.Remove;
                    System.Console.WriteLine("Remove: OperationID " + packmanOperationId + " for " + CurrentXiaomiPackageId);
                    packmanOperationRunning = true;
                }
                GUILayout.EndHorizontal();
            }

            EditorGUI.EndDisabledGroup();
        }