Exemplo n.º 1
0
        static void convertthreadwork()
        {
            while (true)
            {
                Thread.Sleep(1000);
                if (rarqueue.Count > 0)
                {
                    rarmessage newrar = rarqueue.Dequeue();
                    currentwid = newrar.mid;
#if OSSDOWNLOAD
                    OssClient    client     = new OssClient(Config.Endpoint, Config.AccessKeyId, Config.AccessKeySecret);
                    const string bucketName = "coresnow-circle";
                    try
                    {
                        var result = client.GetObject(bucketName, newrar.rarpath);

                        using (var requestStream = result.Content)
                        {
                            string path = @"F:\uev";//\Content;
                            path = signidpropath;
                            Utility.SubDirectoryDelete(path + "/Content");
                            using (var fs = File.Open(path + "/Saved/x.rar", FileMode.Create))
                            {
                                int length = 4 * 1024;
                                var buf    = new byte[length];
                                do
                                {
                                    length = requestStream.Read(buf, 0, length);
                                    fs.Write(buf, 0, length);
                                } while (length != 0);
                            }
                            Console.WriteLine("writefileok :" + result.ContentLength);
                            string apppath = @"E:\Program Files\7-Zip\7zG.exe";
                            apppath = zip7app;
                            string passArguments = "x F:/uev/Saved/x.rar -oF:/uev/Content";
                            passArguments = zip7appargument;
                            Process z7p = Utility.CommandRun(apppath, passArguments);
                            z7p.WaitForExit();

                            IPAddress ipAd = IPAddress.Parse("192.168.1.240");
                            ipAd = IPAddress.Parse(tcplocal);
                            TcpListener myList = new TcpListener(ipAd, 8003);
                            myList.Start();
                            string projectpath = @"F:\uev/pro422.uproject";
                            string Arguments   = "";
                            projectpath = unrealprojectpath;
                            Arguments   = projectshouldlaunched;
                            Process   mpro      = Utility.CommandRun(projectpath, Arguments);
                            Socket    st        = myList.AcceptSocket();
                            TCPClient tcpClient = new TCPClient(st);
                            tcpClient.mtcplistener = myList;
                            tcpClient.mprocess     = mpro;
                        }
                    }
                    catch (Exception e)
                    {
                        window_file_log.Log(" mmessage.rarpath :" + e);

                        var payload = new Dictionary <string, string>
                        {
                            { "result", "failure" },
                            { "reason", "访问的RAR文件不存在" },
                            { "mid", Program.currentwid },
                        };
                        string      strPayload   = JsonConvert.SerializeObject(payload);
                        HttpContent httpContent  = new StringContent(strPayload, Encoding.UTF8, "application/json");
                        int         retrycounter = 0;
retry:
                        window_file_log.Log("retrycounter :" + retrycounter);
                        window_file_log.Log(strPayload);
                        int shouldretry = 0;
                        HttpclientHelper.httppost(Program.remotehttpserver, httpContent, (ref string strparameter, ref byte[] bytearray) => {
                            window_file_log.Log(strparameter);
                            if (!String.IsNullOrEmpty(strparameter))
                            {
                                if (!strparameter.Contains("\"data\":true"))
                                {
                                    shouldretry = 1;
                                    retrycounter++;
                                }
                            }
                        });
                        if (shouldretry == 1 && retrycounter < 10)
                        {
                            Thread.Sleep(1000 * 60 * 10);
                            goto retry;
                        }
                    }
#else //httpdownload
                    HttpclientHelper.httpget(newrar.rarpath, (ref string str, ref byte[] bytearray) => {
                        string path = AppDomain.CurrentDomain.BaseDirectory;
                        path       += "x.rar";
                        path        = @"F:\uev";//\Content;
                        Utility.SubDirectoryDelete(path + "/Content");
                        //Thread.Sleep(5000);
                        File.WriteAllBytes(path + "/Saved/x.rar", bytearray);
                        Console.WriteLine("writefileok :" + bytearray.Length);
                        //Thread.Sleep(5000);
                        string apppath       = @"E:\Program Files\7-Zip\7zG.exe";
                        string passArguments = "x F:/uev/Saved/x.rar -oF:/uev/Content";
                        Process z7p          = Utility.CommandRun(apppath, passArguments);
                        z7p.WaitForExit();

                        IPAddress ipAd     = IPAddress.Parse("192.168.1.240");
                        TcpListener myList = new TcpListener(ipAd, 8003);
                        myList.Start();
                        string projectpath     = @"F:\uev/pro422.uproject";
                        string Arguments       = "";
                        projectpath            = @"C:\Program Files\Epic Games\UE_4.22\Engine\Binaries\Win64/UE4Editor.exe";
                        Arguments              = @"F:\uev/pro422.uproject";
                        Process mpro           = Utility.CommandRun(projectpath, Arguments);
                        Socket st              = myList.AcceptSocket();
                        TCPClient tcpClient    = new TCPClient(st);
                        tcpClient.mtcplistener = myList;
                        tcpClient.mprocess     = mpro;
                    });
#endif
                    evtObj.WaitOne();
                }
            }
        }
        void messagehandler(byte[] buffer)
        {
            try
            {
#if UTF16
                var str = System.Text.Encoding.Unicode.GetString(buffer);
#else
                var str = System.Text.Encoding.UTF8.GetString(buffer);
#endif

                FMessagePackage mp = JsonConvert.DeserializeObject <FMessagePackage>(str);
                switch (mp.MT)
                {
                case MessageType.ASSIGNOK:
                    string androidkey = "";
                    string ioskey     = "";
                    string result     = "success";
                    string reason     = "";
                    Thread.Sleep(6000);
                    if (mprocess != null && !mprocess.HasExited)
                    {
                        mprocess.Kill();
                    }
                    if (mp.PayLoad != "" && mp.PayLoad != "None")
                    {
                        //content copy begin
                        string sourcepath = @"F:\uev\Content";
                        sourcepath = Program.signidpropath + "/Content";
                        ////////////////////////////////////////////////////////////////////////
                        ///////////////////////////////resource prepare for android
                        string despath = Program.packagpropath_android + "/Content";
                        Utility.SubDirectoryDelete(despath);
                        Utility.DirectoryCopy(sourcepath, despath, true);
                        //content copy end
                        //delete old data begin
                        string pakpath = Program.packagpropath_android + "/Saved";
                        Utility.SubDirectoryDelete(pakpath);
                        //delete old data end
                        //////////////////////////////////////////////////////////////////
                        ////////////////////////cook for Android begin
                        string  path        = Program.unrealbatchfilepath;
                        string  Arguments   = Program.argumentsforandroid;
                        Process tempprocess = Utility.CommandRun(path, Arguments);
                        tempprocess.WaitForExit();
                        /////////////////////////////////////////////////////////////////
                        /////////////////////////cook for Android end
                        ////////////////////////////////////////////////////////////////////////
                        ///////////////////////////////resource prepare for ios
                        despath = Program.packagpropath_ios + "/Content";
                        Utility.SubDirectoryDelete(despath);
                        Utility.DirectoryCopy(sourcepath, despath, true);
                        //content copy end
                        //delete old data begin
                        pakpath = Program.packagpropath_ios + "/Saved";
                        Utility.SubDirectoryDelete(pakpath);
                        //////////////////////////////////////////////////////////////////
                        ////////////////////////cook for ios begin
                        Arguments   = Program.argumentsforios;
                        tempprocess = Utility.CommandRun(path, Arguments);
                        tempprocess.WaitForExit();
                        /////////////////////////////////////////////////////////////////
                        /////////////////////////cook for ios end

                        //Console.WriteLine("hi");
                        string androidpaksfilepath = Program.packagpropath_android + "/Saved/StagedBuilds/Android/InfiniteLife1_0/Content/Paks/pakchunk1-Android.pak";
                        string iospaksfilepath     = Program.packagpropath_ios + "/Saved/StagedBuilds/IOS/cookeddata/infinitelife1_0/content/paks/pakchunk1-ios.pak";
                        Guid   g;
                        // Create and display the value of two GUIDs.
                        g = Guid.NewGuid();
                        string guidstring  = g.ToString();
                        string androidguid = guidstring + ".pak";
                        g          = Guid.NewGuid();
                        guidstring = g.ToString();
                        string       iosguid    = guidstring + ".pak";
                        OssClient    client     = new OssClient(Config.Endpoint, Config.AccessKeyId, Config.AccessKeySecret);
                        const string bucketName = "coresnow-circle";
                        androidkey = "model/" + androidguid;
                        client.PutObject(bucketName, androidkey, androidpaksfilepath);
                        ioskey = "model/" + iosguid;
                        client.PutObject(bucketName, ioskey, iospaksfilepath);
                        result = "success";
                        reason = "";
                    }
                    else
                    {
                        result = "failure";
                        reason = "资产无效";
                    }
                    Program.evtObj.Set();    //next one
                    var payload = new Dictionary <string, string>
                    {
                        { "result", result },
                        { "reason", reason },
                        { "mid", Program.currentwid },
                        { "assetpath", mp.PayLoad },//if this value is null then this asset is invalid
                        { "android_pak", androidkey },
                        { "ios_pak", ioskey }
                    };
                    string      strPayload   = JsonConvert.SerializeObject(payload);
                    HttpContent httpContent  = new StringContent(strPayload, Encoding.UTF8, "application/json");
                    int         retrycounter = 0;
retry:
                    window_file_log.Log("retrycounter :" + retrycounter);
                    window_file_log.Log(strPayload);
                    int shouldretry = 0;
                    HttpclientHelper.httppost(Program.remotehttpserver, httpContent, (ref string strparameter, ref byte[] bytearray) => {
                        window_file_log.Log(strparameter);
                        if (!String.IsNullOrEmpty(strparameter))
                        {
                            if (!strparameter.Contains("\"data\":true"))
                            {
                                shouldretry = 1;
                                retrycounter++;
                            }
                        }
                    });
                    if (shouldretry == 1 && retrycounter < 10)
                    {
                        Thread.Sleep(1000 * 60 * 10);
                        goto retry;
                    }
                    //Program.evtObj.Set();
                    OnClientExit();
                    break;

                case MessageType.EMPTY:

                    break;

                default:

                    break;
                }
            }
            catch (Newtonsoft.Json.JsonSerializationException)
            {//buffer all zero//occur when mobile client force kill the game client
                OnClientExit();
            }
        }