Пример #1
0
            public bool InitiateInstall(PkgInfo pkgInfo, bool skipInstallCheck, out long id)
            {
                id = 0;
                if (!skipInstallCheck && TryRecoverTaskID(pkgInfo, out id))
                {
                    if (id == -1)       //App is already installed and no id was returned
                    {
                        id = 0xAFFFFFF; //The flag we will use to determine if it is installed
                    }
                    return(true);
                }
                var response = HttpUtil.Post($"http://{PS4IP}:12800/api/install",
                                             HttpUtil.GetInstallJson(pkgInfo.PkgFiles, ServerIp, ServerPort));

                //{ "status": "fail", "error_code": 0x80990004 }
                if (response.Contains("task_id"))
                {
                    id = long.Parse(JToken.Parse(response)["task_id"].ToString());
                    return(true);
                }
                if (response.Contains("{ \"status\": \"fail\""))
                {
                    throw new RPIErrorThrownException(long.Parse(JToken.Parse(response)["error_code"].ToString()));
                }
                return(false);
            }
Пример #2
0
            public bool TryRecoverTaskID(PkgInfo pkgInfo, out long id)
            {
                id = -1;
                id = RecoverTaskID(pkgInfo);
                if (id != -1)
                {
                    return(true);
                }
                //Because it checks the title id instead of content id
                //this will return true if the game is installed
                //there is no way of knowing the patch is installed accurately
                //So we just return false and assume it's not.
                if (pkgInfo.Type == Enums.PkgType.Patch || pkgInfo.Type == Enums.PkgType.Additional_Content)
                {
                    return(false);
                }
                var url      = $"http://{PS4IP}:12800/api/is_exists";
                var json     = $"{{\"title_id\":\"{pkgInfo.TitleID}\"}}";
                var response = HttpUtil.Post(url, json);

                if (response.Contains("task_id"))
                {
                    id = int.Parse(JToken.Parse(response)["task_id"].ToString());
                    return(true);
                }
                Logger.WriteLine("::GetTaskID.AppExists - " + response, Logger.Type.StandardOutput);

                //App is already installed, usually a task ID comes with it but I'm not certain
                //If this happens with DLC/Themes
                //Better safe than sorry
                return(response.Contains("\"exists\": \"true\""));
            }
Пример #3
0
        private void AddItem(PkgInfo pkgInfo)
        {
            //Add To ListView
            ListViewItem listViewItem = new ListViewItem(pkgInfo.Title);

            listViewItem.Tag = pkgInfo.FilePath;
            listViewItem.SubItems.Add(Path.GetFileName(pkgInfo.FilePath));
            listViewItem.SubItems.Add(pkgInfo.Type.ToString());
            listViewItem.SubItems.Add(Enums.TaskType.Queued.ToString());
            this.listViewItemsQueue.InvokeIfRequired(() => listViewItemsQueue.Items.Add(listViewItem));
            QueueItem queueItem = new QueueItem(listViewItem, pkgInfo);

            ps4PkgList.Add(queueItem);
        }
Пример #4
0
            public static void UploadPkg(PkgInfo uploadForm, byte[] fileByte, Action <ResponseModel> callback)
            {
                WWWForm wwwForm = new WWWForm();

                wwwForm.AddBinaryData("file", fileByte);
                wwwForm.AddField("pkg_name", uploadForm.pkg_name);
                wwwForm.AddField("version", uploadForm.version);
                wwwForm.AddField("unity_version", uploadForm.unity_version);
                wwwForm.AddField("pkg_path", uploadForm.pkg_path);
                wwwForm.AddField("author", uploadForm.author);
                wwwForm.AddField("describtion", uploadForm.describtion);
                wwwForm.AddField("help_url", uploadForm.help_url);
                wwwForm.AddField("dependences", uploadForm.dependences);
                wwwForm.AddField("permissions", uploadForm.permissions);
                PostRequest <ResponseModel>(PkgConstant.API_UPLOAD_PKG, wwwForm, callback, true);
            }
Пример #5
0
            private int RecoverTaskID(PkgInfo pkgInfo)
            {
                var url      = $"http://{PS4IP}:12800/api/find_task";
                var json     = $"{{\"content_id\":\"{pkgInfo.ContentID}\", \"sub_type\":{(int)pkgInfo.Type}}}";
                var response = HttpUtil.Post(url, json);

                Logger.WriteLine("::RecoverTaskID - " + response, Logger.Type.StandardOutput);
                if (response.Contains("task_id"))
                {
                    return(int.Parse(JToken.Parse(response)["task_id"].ToString()));
                }
                if (response.Contains("error_code"))
                {
                    throw new RPIErrorThrownException(long.Parse(JToken.Parse(response)["error_code"].ToString()));
                }
                return(-1);
            }
Пример #6
0
    //发送协议逻辑
    private int SendInternal()
    {
        int len = m_pkgList.Count;

        if (len > 0)
        {
            PkgInfo info  = null;
            int     index = 0;
            PkgInfo tempInfo;
            while (index < len)
            {
                tempInfo = m_pkgList[index];
                if (onChkSendPkg(tempInfo.cmd))
                {//包发送条件
                    info = tempInfo;
                    //Log.info("前面的协议包要等角色登录后才能发送,调整发送索引到" + index);
                    break;
                }
                index++;
            }
            if (null == info)
            {
                //Log.info("所有的协议包要等角色登录后才能发送");
                return(0);
            }
            int iRet = 0;
            Log.info("SendInternal Send pkg: " + info.cmd);
            //Log.info("pkg len: " + info.bufferLen);
            //Log.info("pkg buffer len: " + info.buffer.Length);
            iRet = m_TgcpHandle.Send(info.buffer, info.bufferLen, info.timeoutInterval);

            if (0 != iRet)
            {
                Log.info("after send,happend error: " + iRet);
                return(iRet);
            }
            m_pkgList.RemoveAt(index);
            m_networkTimeoutMonitor.SendPkg((UInt16)CS_CMD_ID.CS_SYN_TIME == info.cmd);
        }
        return(0);
    }
Пример #7
0
        public static void UploadPackage(UploadInfo uploadInfo)
        {
            // MultyFrameworkEditorTool.CreateVersionJson(uploadInfo.assetPath, uploadInfo);
            AssetDatabase.ExportPackage(uploadInfo.assetPath, uploadInfo.name + ".unitypackage",
                                        ExportPackageOptions.Recurse);
            byte[]  bytes = File.ReadAllBytes("Assets/../" + uploadInfo.name + ".unitypackage");
            PkgInfo form  = new PkgInfo()
            {
                unity_version = uploadInfo.unityVersion,
                author        = uploadInfo.author,
                pkg_path      = uploadInfo.assetPath,
                pkg_name      = uploadInfo.name,
                version       = uploadInfo.version,
                dependences   = "",
                permissions   = uploadInfo.isPublic
                    ? PkgConstant.PKG_PERMISSIONS_PUBLIC
                    : PkgConstant.PKG_PERMISSIONS_PRIVATE,
                help_url    = uploadInfo.helpurl,
                describtion = uploadInfo.describtion,
            };

            for (int i = 0; i < uploadInfo.dependences.Count; i++)
            {
                form.AddDependences(uploadInfo.dependences[i]);
            }

            HttpPkg.UploadPkg(form, bytes, (m) =>
            {
                string source = "Assets/../" + uploadInfo.name + ".unitypackage";
                string dest   = Path.Combine(localPkgPath, uploadInfo.name + "_" + uploadInfo.version + ".unitypackage");
                if (File.Exists(dest))
                {
                    File.Delete(dest);
                }
                File.Move(source, dest);
                FreshWebCollection();
            });
        }
Пример #8
0
        private bool SanitizePathNeeded(PkgInfo pkgInfo, out FileRenameInfo fileRenameInfo)
        {
            fileRenameInfo = null;
            var pattern         = @"^[\\a-zA-Z0-9-_\.]+$";
            var currentFileName = Path.GetFileName(pkgInfo.FilePath);
            var match           = Regex.Match(currentFileName, pattern);

            if (!Regex.IsMatch(currentFileName, pattern))
            {
                fileRenameInfo = new FileRenameInfo()
                {
                    CurrentName = currentFileName,
                    CurrentPath = Path.GetFullPath(pkgInfo.FilePath),
                };

                pattern = pattern.Substring(1, pattern.Length - 2);
                string newFileName = "";
                var    newMatch    = Regex.Match(currentFileName, pattern);
                while (newMatch.Success)
                {
                    newFileName += newMatch.Value;
                    newMatch     = newMatch.NextMatch();
                }
                int maxFileNameSize = 60;
                if (newFileName.Length > maxFileNameSize)
                {
                    //PS4 only seems to like titles < 60 (including ".pkg")
                    //So we eliminate the remainder from the start
                    //this is only used for renaming files, nothing more
                    //so it does not matter if the name looks weird. It's only temporary :)
                    newFileName = newFileName.Remove(0, newFileName.Length - maxFileNameSize);
                }
                fileRenameInfo.WantedName = newFileName;
                return(true);
            }
            return(false);
        }
Пример #9
0
            public bool Uninstall(PkgInfo pkgInfo)
            {
                var url  = $"http://{PS4IP}:12800/api/uninstall_";
                var json = "";

                switch (pkgInfo.Type)
                {
                case Enums.PkgType.Game:
                    url += "game";
                    json = $"{{\"title_id\":\"{pkgInfo.TitleID}\"}}";
                    break;

                case Enums.PkgType.Patch:
                    json = $"{{\"title_id\":\"{pkgInfo.TitleID}\"}}";
                    url += "patch";
                    break;

                case Enums.PkgType.Additional_Content:
                    url += "ac";
                    json = $"{{\"content_id\":\"{pkgInfo.ContentID}\"}}";
                    break;

                case Enums.PkgType.Addon_Theme:
                    url += "theme";
                    json = $"{{\"content_id\":\"{pkgInfo.ContentID}\"}}";
                    break;
                }

                var response = HttpUtil.Post(url, json);

                if (response.Contains("success"))
                {
                    return(true);
                }
                return(false);
            }
Пример #10
0
            public void StartServer(PkgInfo info)
            {
                foreach (var proc in NodeJSUtil.GetNodeProcesses())
                {
                    NodeJsProcessSet.Add(proc.Id);
                }

                Logger.WriteLine("::StartServer - Starting server in directory " + Path.GetDirectoryName(info.FilePath), Logger.Type.StandardOutput);
                var cmdProcess = new Process();
                var path       = Path.GetDirectoryName(info.FilePath);

                cmdProcess.StartInfo.FileName               = "cmd.exe";
                cmdProcess.StartInfo.Arguments              = $"/C http-server \"{path}\" -p {GetNextBestPort()}";
                cmdProcess.StartInfo.UseShellExecute        = false;
                cmdProcess.StartInfo.CreateNoWindow         = true;
                cmdProcess.StartInfo.RedirectStandardOutput = true;
                cmdProcess.StartInfo.RedirectStandardError  = true;
                if (Directory.GetLogicalDrives().Contains(path))
                {
                    cmdProcess.StartInfo.Arguments = cmdProcess.StartInfo.Arguments.Replace(@"\", @"\\");
                }
                cmdProcess.Start();

                //Assumption will be that it should always be found
                currentProcessPid = 0;
                while (currentProcessPid == 0)
                {
                    try {
                        currentProcessPid = NodeJSUtil.GetNodeProcesses()
                                            .ToList()
                                            .Find(proc => !NodeJsProcessSet.Contains(proc.Id))
                                            .Id;
                    } catch (Exception) {
                    }
                    System.Threading.Thread.Sleep(100);
                }


                var temp = cmdProcess;

                System.Threading.Tasks.Task.Run(() => {
                    while (temp.Handle == IntPtr.Zero)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    var stdout = "";
                    while (stdout != null)
                    {
                        stdout = temp.StandardOutput.ReadLine();
                        if (stdout != null)
                        {
                            Logger.WriteLine(stdout, Logger.Type.StandardOutput);
                        }
                    }
                });

                System.Threading.Tasks.Task.Run(() => {
                    while (temp.Handle == IntPtr.Zero)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    var stderr = "";
                    while (stderr != null)
                    {
                        stderr = temp.StandardError.ReadLine();
                        if (stderr != null)
                        {
                            if (stderr.Contains("EADDRINUSE"))
                            {
                                server.IsRunning = false;
                                break;
                            }
                        }
                        Logger.WriteLine(stderr, Logger.Type.StandardOutput);
                    }
                });
                IsRunning = true;
            }
Пример #11
0
        private void AddAllValidItems(string[] paths)
        {
            var            pkgFilePaths = GetFilesForFileExtension(".pkg", paths, true);
            List <PkgInfo> pkgList      = new List <PkgInfo>();
            List <PkgInfo> patchesList  = new List <PkgInfo>();

            foreach (var filePath in pkgFilePaths)
            {
                var pkgFilePath = filePath;
                var fileName    = Path.GetFileName(pkgFilePath);
                if (fileName.Contains(" "))
                {
                    fileName    = fileName.Replace(" ", ".");
                    pkgFilePath = pkgFilePath.Substring(0, pkgFilePath.Length - fileName.Length) + fileName;
                    File.Move(filePath, pkgFilePath);
                }

                try {
                    var     pkg     = PS4_Tools.PKG.SceneRelated.Read_PKG(pkgFilePath);
                    PkgInfo pkgInfo = new PkgInfo();
                    pkgInfo.FilePath  = pkgFilePath;
                    pkgInfo.TitleID   = pkg.Param.TitleID;
                    pkgInfo.Title     = pkg.Param.Title;
                    pkgInfo.Version   = pkg.Param.APP_VER;
                    pkgInfo.Type      = Enums.Parser.Parse(pkg.PKG_Type);
                    pkgInfo.ContentID = pkg.Content_ID;
                    pkgInfo.PkgFiles  = new string[] { Path.GetFileName(pkgFilePath) };

                    if (pkgInfo.Type == Enums.PkgType.Patch)
                    {
                        patchesList.Add(pkgInfo);
                    }
                    else
                    {
                        AddItem(pkgInfo);
                    }
                } catch { }
            }


            //Handles multiple patches edge case
            var patchDict = new Dictionary <string, List <string> >();

            foreach (var patch in patchesList)
            {
                if (!patchDict.ContainsKey(patch.TitleID))
                {
                    patchDict.Add(patch.TitleID, new List <string>());
                }

                if (System.Text.RegularExpressions.Regex.IsMatch(patch.FilePath, @"([A-Za-z0-9-_]+_\d.pkg)+"))
                {
                    patchDict[patch.TitleID].Add(Path.GetFileName(patch.FilePath));
                }
            }

            for (int i = 0; i < patchesList.Count; ++i)
            {
                var filePaths = patchDict[patchesList[i].TitleID];
                if (filePaths.Count == 0)
                {
                    filePaths.Add(Path.GetFileName(patchesList[i].FilePath));
                }
                patchesList[i].PkgFiles = filePaths.ToArray();
                AddItem(patchesList[i]);
            }

            //Order by games -> patch -> DLC -> themes so nothing goes wrong
            //This will not change the order in the list view
            //But it is not necessary anyway, as each object has an instance
            //To the UI
            ps4PkgList.Sort();
            ResizeListViewColumns(this.listViewItemsQueue, listViewHwnd);
        }
Пример #12
0
            public void StartServer(PkgInfo info)
            {
                foreach (var proc in NodeJSUtil.GetNodeProcesses())
                {
                    NodeJsProcessSet.Add(proc.Id);
                }
                Logger.WriteLine("::StartServer - Starting server in directory " + Path.GetDirectoryName(info.FilePath), Logger.Type.StandardOutput);
                var cmdProcess = new Process();
                var path       = Path.GetDirectoryName(info.FilePath);

                cmdProcess.StartInfo.FileName               = "cmd.exe";
                cmdProcess.StartInfo.Arguments              = $"/C http-server \"{path}\" -p {GetNextBestPort()}";
                cmdProcess.StartInfo.UseShellExecute        = false;
                cmdProcess.StartInfo.CreateNoWindow         = true;
                cmdProcess.StartInfo.RedirectStandardOutput = true;
                cmdProcess.StartInfo.RedirectStandardError  = true;
                if (Directory.GetLogicalDrives().Contains(path))
                {
                    cmdProcess.StartInfo.Arguments = cmdProcess.StartInfo.Arguments.Replace(@"\", @"\\");
                }
                cmdProcess.Start();

                //Assumption will be that it should always be found
                currentProcessPid = 0;
                while (currentProcessPid == 0)
                {
                    try {
                        var nodeProcesses = NodeJSUtil.GetNodeProcesses().ToList();
                        if (nodeProcesses.Count > 0)
                        {
                            currentProcessPid = nodeProcesses
                                                .Find(proc => !NodeJsProcessSet.Contains(proc.Id))
                                                .Id;
                        }
                    } catch (Exception e) {
                    }
                    System.Threading.Thread.Sleep(100);
                }

                var temp = cmdProcess;

                while (temp.Handle == IntPtr.Zero)
                {
                    System.Threading.Thread.Sleep(100);
                }

                Stopwatch stopwatchTimeoutTracker = new Stopwatch();

                stopwatchTimeoutTracker.Start();
                IsRunning = false;

                //Couldn't think of a better solution
                //Just gotta hope this works well
                //Otherwise we'll be stuck here forever :(
                var stdout = "";

                while (stdout != null)
                {
                    stdout = temp.StandardOutput.ReadLine();
                    if (stdout != null)
                    {
                        if (stdout.ToLower().Contains("starting up http-server, serving"))
                        {
                            IsRunning = true;
                            break;
                        }
                        Logger.WriteLine(stdout, Logger.Type.StandardOutput);
                    }
                }

                if (!IsRunning && temp.HasExited)
                {
                    var strdErr = temp.StandardError.ReadToEnd();
                    if (strdErr.Contains("EADDRINUSE"))
                    {
                        throw new ServerInitializationException("Address already in use");
                    }
                }
            }