Пример #1
0
        public TestDownloadEngine(string ip, int port)
        {
            Debug.LogWarning("TestDownloadEngien is deprecated, might not work");

            ClientEngine client = new ClientEngine(ip, port);

            DownloadEngine engine = new DownloadEngine(client, "TESTTOKEN");

            string wp = engine.ReceiveData();

            //string data = engine.ReceiveData();


            if (File.Exists(outpuFileName))
            {
                File.Delete(outpuFileName);
            }
            stream = File.Create(outpuFileName);



            Stopwatch watch = new Stopwatch();

            watch.Start();

            Debug.Log("Downloading...");
            byte[] bytes = engine.ReceiveDataRaw();
            watch.Stop();

            Debug.Log("Download Complete\nBytes lenght: " + stream.Position);

            Debug.Log("Time elapsed: " + watch.ElapsedMilliseconds);
            Debug.Log("Averge speed: " + (stream.Position / ((float)watch.ElapsedMilliseconds / 1000f)) + "B/s ");


            //Debug.Log("Received engine data: ");
            //Debug.Log(data);



            //byte[] bytes = Encoding.ASCII.GetBytes(data);

            //file.Write(bytes, 0, bytes.Length);

            //file.Close();

            stream.Close();
        }
Пример #2
0
        public void DownloadThread()
        {
            /*if (downloadEngine == null)
             * {
             *  downloadEngine = new DownloadEngine(StoreClient.createNewClient(ipAddress, port), token);
             * }*/
            while (true)
            {
                while (queue.Count == 0)
                {
                    Thread.Sleep(100);
                }

                QueueEntry entry = queue[0];

                downloadEngine = new DownloadEngine(StoreClient.createNewClient(ipAddress, port), entry.token);

                if (entry.type == DownloadTypes.game)
                {
                    downloadEngine.DownloadGame(entry.id, entry.path, entry.completeFunction);
                }
                else if (entry.type == DownloadTypes.icon)
                {
                    downloadEngine.DownloadIcon(entry.id, entry.path, entry.completeFunction, entry.highResImage);
                }



                while (downloadEngine.working)
                {
                    Thread.Sleep(100);
                }

                queue.RemoveAt(0);
            }
        }