Esempio n. 1
0
        public void SyncJobs(String fileName)
        {
            if (syncInProgress)
            {
                return;
            }
            syncInProgress = true;


            ILog lg = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            lg.Debug("Start syncing");
            try
            {
                String folderPathGameSiiZero = fileName;
                String folderPathSave        = Path.GetDirectoryName(fileName);
                String folderPathGameSii     = Path.Combine(folderPathSave, "game.sii");


                try
                {
                    if (Rn.Config.General.PlaySound)
                    {
                        SoundPlayer sp = new SoundPlayer(@"sound\sound_send.wav");
                        sp.Play();
                    }


                    if (Rn.Config.General.BackupSaveGame)
                    {
                        File.Move(folderPathGameSii, folderPathGameSii + "." + DateTime.Now.ToFileTime() + ".bak");
                    }
                }
                catch (Exception e)
                {
                }


                // Get PHP Session ID
                HTTPRequest http = new HTTPRequest();
                http.BaseUrl = "http://www.ets2sync.com/de/";
                http.Request();


                http.CreateFullUrl("file_upload.php?uploadfile=game.sii.0");
                http.UploadFile(folderPathGameSiiZero, "uploadfile", "application/octet-stream");

                Response.UploadFile resp = fastJSON.JSON.ToObject <Response.UploadFile>(http.Response);

                List <String> dlcs = new List <String>();
                if (this.DlcGoingEast)
                {
                    dlcs.Add("east");
                }
                if (this.DlcHighPowerCargoes)
                {
                    dlcs.Add("hpower");
                }
                if (this.DlcScandinavia)
                {
                    dlcs.Add("north");
                }

                String dlcPost = String.Join(",", dlcs);

                http.CreateFullUrl("engine.php");
                http.Post = "dlcs=" + dlcPost + "&f_path_orig=" + resp.file_path + "&f_path_synced=" + resp.f_path_synced;
                http.Request();
                //http://www.ets2sync.com/de/downloader.php?file=synced

                http.CreateFullUrl("file_list.php");
                http.Post = "file=synced";
                http.Request();


                //http://www.ets2sync.com/de/downloader.php?file=synced
                http.CreateFullUrl("downloader.php?file=synced");
                http.DownloadFile(folderPathGameSii);


                try
                {
                    if (Rn.Config.General.PlaySound)
                    {
                        SoundPlayer sp = new SoundPlayer(@"sound\sound_receive.wav");
                        sp.Play();
                    }
                }
                catch (Exception e)
                {
                }
            }
            catch (Exception e)
            {
                if (Rn.Config.General.PlaySound)
                {
                    SoundPlayer sp = new SoundPlayer(@"sound\sound_error.wav");
                    sp.Play();
                }
            }


            lg.Debug("End syncing");
            syncInProgress = false;
        }