Beispiel #1
0
        public DownloadEngine DownloadGame(Int64 id, string token, Action <DownloadEngine.DownloadStatus, long, DownloadManager.DownloadTypes> downloadCompleteFunction = null)
        {
            //DownloadEngine downloadEngine = new DownloadEngine(createNewClient(ipAddress, downloadEnginePort), token);

            /*if(downloadEngine == null)
             * {
             *  downloadEngine = new DownloadEngine(createNewClient(ipAddress, downloadEnginePort), token);
             * }*/

            if (downloadManager == null)
            {
                downloadManager = new DownloadManager(ipAddress, downloadEnginePort);
            }

            int empty = -1;

            Library.Game game = Library.FindGame(id, out empty);
            if (game == null)
            {
                Debug.LogError("Game with id " + id + " not found!!!");
                return(null);
            }
            Debug.Log("Downloading game...");
            if (!Directory.Exists(gamesPath + game.path))
            {
                Directory.CreateDirectory(gamesPath + game.path);
            }
            //downloadEngine.DownloadGame(id, gamesPath + game.path + game.fileName, downloadCompleteFunction);

            return(downloadManager.DownloadGame(id, token, gamesPath + game.path + game.fileName, downloadCompleteFunction));
        }
        private void SetQueueTexts()
        {
            if (!downloadQueueView.Dispatcher.CheckAccess())
            {
                downloadQueueView.Dispatcher.BeginInvoke(new Action(SetQueueTexts));
                return;
            }

            downloadQueueView.Children.RemoveRange(1, downloadQueueView.Children.Count);

            List <DownloadManager.QueueEntry> entries = dwManager.queue;

            for (int i = 1; i < entries.Count; i++)
            {
                Library.Game game = Library.FindGame(entries[i].id);
                if (game == null)
                {
                    Debug.LogError("Something went desperately wrong, cannot find game with id " + dwManager.queue[0].id);
                    return;
                }

                StringReader reader    = new StringReader(gameTextBlockPrefab);
                XmlReader    xmlReader = XmlReader.Create(reader);
                TextBlock    newButton = (TextBlock)XamlReader.Load(xmlReader);

                newButton.Text = game.name;


                downloadQueueView.Children.Add(newButton);
            }
        }
        public void OnGameClick(object sender, MouseButtonEventArgs e)
        {
            TextBlock textBlock = (TextBlock)sender;

            Debug.Log(textBlock.Text + " clicked");

            int    id    = -1;
            string idStr = MUtil.GetStringToSpecialChar(textBlock.Text, ')');

            if (!int.TryParse(idStr, out id))
            {
                Debug.ConversionError(idStr, "id", id);
                return;
            }

            if (id > targetUserGames.Count || id < 0)
            {
                Debug.LogError("Bad ID");
                return;
            }

            targetGame = targetUserGames[id];
            //UpdateUserGamesDisplay();

            ResetGamesListColors();

            textBlock.Foreground = selectedGameColor;
        }
        private void ClearUserInfo()
        {
            targetUser = null;
            targetUserGames.Clear();
            targetGame = null;

            GamesSP.Children.Clear();

            //ResetGamesListColors();
        }
        private void AddGame(Library.Game game)
        {
            StringReader reader    = new StringReader(gamePrefab);
            XmlReader    xmlReader = XmlReader.Create(reader);
            TextBlock    newButton = (TextBlock)XamlReader.Load(xmlReader);

            newButton.Text = game.ToString();

            newButton.MouseLeftButtonDown += OnGameClick;

            GamesSP.Children.Add(newButton);
        }
        public void DisplayGameInfo(Library.Game _game)
        {
            game = _game;

            if (game == null)
            {
                Debug.LogError("Game reference is null, quitting");
                return;
            }

            GameName.Text         = game.name;
            diskSizeText.Text     = game.diskSize.ToStringWithPrecision(1);
            downloadSizeText.Text = game.downloadSize.ToStringWithPrecision(1);
        }
Beispiel #7
0
        private void _DownloadGame(Int64 id, string outputFile)
        {
            RequestStatus requestStatus = RequestGameFromServer(id);

            switch (requestStatus)
            {
            case RequestStatus.unknown:
                Debug.LogError("Unknown download error");
                FinishDownloading(DownloadStatus.unknown, id);
                return;

            case RequestStatus.success:
                break;

            case RequestStatus.fileNotFound:
                Debug.LogError("Game not found on server");
                FinishDownloading(DownloadStatus.fileNotFoundOnServer, id);
                return;

            case RequestStatus.connectionLost:
                Debug.LogError("Connection lost");
                FinishDownloading(DownloadStatus.connectionLost, id);
                return;

            case RequestStatus.notAuthorised:
                Debug.LogError("Not authorised to download");
                FinishDownloading(DownloadStatus.notAuthorised, id);
                return;

            default:
                Debug.LogError("Unknown download error");
                FinishDownloading(DownloadStatus.unknown, id);
                return;
            }



            //Create file
            stream = File.Create(outputFile);

            //string testReceive = client.WaitForReceive();
            //Debug.Log("Test receive: " + testReceive);

            long size = -1;

            Library.Game game = Library.FindGame(id);
            if (game != null)
            {
                size = game.downloadSize.bytes;
                Debug.Log("Download bytes: " + size);
            }

            //Download
            ReceiveDataRaw(size);

            stream.Close();
            Debug.Log("Closed stream");
            Debug.Log("Downloaded " + downloadedDataSize + " bytes");

            DownloadStatus status = DownloadStatus.success;



            FinishDownloading(status, id);
            return;
        }
        private void SetValues()
        {
            Library.Game game = Library.FindGame(dwManager.queue[0].id);
            if (game == null)
            {
                Debug.LogError("Something went desperately wrong, cannot find game with id " + dwManager.queue[0].id);
                return;
            }

            if (!actuallyDownloadingName.Dispatcher.CheckAccess())
            {
                actuallyDownloadingName.Dispatcher.Invoke(new Action(SetValues));
                return;
            }

            actuallyDownloadingName.Text = game.name;

            if (dwManager.downloadEngine == null)
            {
                Debug.LogError("Download engine is null");
                Thread.Sleep(1000);
                return;
            }

            double percentage = dwManager.downloadEngine.downloadedDataSize * 100f / game.downloadSize.bytes;

            acutallyDownloadingProgressBar.Value = percentage;

            actuallyDownloadingPercentage.Text = ((int)percentage).ToString() + "%";


            //Speed measure
            measuredSizes[measuredSizesIndex].bytes = dwManager.downloadEngine.downloadedDataSize;
            measuredSizesIndex++;
            if (measuredSizesIndex == measuredSizes.Length)
            {
                measuredSizesIndex = 0;
                long sum = 0;
                for (int i = 1; i < measuredSizes.Length; i++)
                {
                    sum += measuredSizes[i].bytes - measuredSizes[i - 1].bytes;
                }

                long averge = (long)(sum / (float)(measuredSizes.Length - 1) * 1000f / measureInterval);

                Library.Game.Size newSize = new Library.Game.Size(averge);

                actuallyDownloadingSpeed.Text = newSize.ToStringWithPrecision(2) + "/s";
            }


            if (lastGameID != game.id)
            {
                string iconPath = AppDomain.CurrentDomain.BaseDirectory + Library.iconsPath + game.id.ToString() + "_1.png";

                if (File.Exists(iconPath))
                {
                    actuallyDownloadingIcon.Source = new BitmapImage(new Uri(iconPath));
                    lastGameID = game.id;
                }
                else
                {
                    Library.iconsDownloader.DownloadIcon(game.id, Library.userInfo.token, iconPath, IconDownloaded, false, true);
                    lastGameID = game.id;
                }
            }
        }
        public List <Library.Game> RequestUserLibrary(long id)
        {
            string library = AdminCommands.GetUserGamesList(id); //client.RequestLibrary();

            List <Library.Game> games = new List <Library.Game>();

            int gameListSize = 0;

            for (int i = 0; i < library.Length; i++)
            {
                if (library[i] == '\n')
                {
                    gameListSize++;
                }
            }

            Int64[] gamesIDs = new Int64[gameListSize];


            string gameID     = "";
            int    actualGame = 0;

            for (int i = 0; i < library.Length; i++)
            {
                if (library[i] == '\n')
                {
                    if (!long.TryParse(gameID, out gamesIDs[actualGame]))
                    {
                        Debug.LogError("Cannot parse " + gameID);
                    }
                    else
                    {
                        actualGame++;
                    }



                    gameID = "";
                }
                else
                {
                    gameID += library[i];
                }
            }

            for (int i = 0; i < gameListSize; i++)
            {
                Library.Game game = Library.ParseStringToGame(App.storeClient.RequestGameInfo(gamesIDs[i]));
                if (game == null)
                {
                    Debug.LogError("Something gone desperatelly wrong, game info not found in client memory");
                }


                games.Add(game);

                //AddGameToTheList(game);
            }

            return(games);
        }