Beispiel #1
0
        /// <summary>
        /// Downloads the zip file of the map from the workshop
        /// </summary>
        /// <param name="self">The WorkshopFile object</param>
        /// <param name="path">Path to download to, ".zip" file</param>
        public static void download(WorkshopFile self, string outputFolder)
        {
            //Make sure its actually a folder, not a file
            if (Path.HasExtension(outputFolder))
            {
                throw new ArgumentException("pathname must reference a folder", "outputFolder");
            }
            else
            {
                outputFolder += "/";//make sure it will place stuff in the folder, not an instance of its name + var

                //Create the directory if it doesn't exist
                if (!Directory.Exists(outputFolder))
                {
                    Directory.CreateDirectory(outputFolder);
                }

                //Download the file from the workshop
                using (var client = new WebClient())
                {
                    client.DownloadFile(self.response.publishedfiledetails[0].file_url, outputFolder + "download.zip");
                }

                //Extract the zip
                using (var zip = ZipFile.OpenRead(outputFolder + "download.zip"))
                {
                    foreach (var entry in zip.Entries.ToList())
                    {
                        entry.ExtractToFile(outputFolder + entry.FullName, true); //Extract the file to its download folder
                    }
                }
            }
        }
Beispiel #2
0
        public static void monitoredDownload(WorkshopFile self, string outputFolder, Action <int, int> callback, Action downloadComplete)
        {
            //Make sure its actually a folder, not a file
            if (Path.HasExtension(outputFolder))
            {
                throw new ArgumentException("pathname must reference a folder", "outputFolder");
            }
            else
            {
                outputFolder += "/";//make sure it will place stuff in the folder, not an instance of its name + var

                //Create the directory if it doesn't exist
                if (!Directory.Exists(outputFolder))
                {
                    Directory.CreateDirectory(outputFolder);
                }

                WebClient client = new WebClient();
                client.DownloadProgressChanged += (object o, DownloadProgressChangedEventArgs e) =>
                {
                    callback((int)e.BytesReceived, (int)e.TotalBytesToReceive); //Report progress
                };

                //WRONG HANDLER TYPE. TODO: FIX THIS AND MAKE IT FIRE WHEN DOWNLOAD COMPLETE!
                client.DownloadFileCompleted += (sender, e) =>
                {
                    Console.WriteLine("download complete");
                    //Extract the zip
                    using (var zip = ZipFile.OpenRead(outputFolder + "download.zip"))
                    {
                        foreach (var entry in zip.Entries.ToList())
                        {
                            entry.ExtractToFile(outputFolder + entry.FullName, true); //Extract the file to its download folder
                        }
                    }

                    downloadComplete();
                };

                //Download the file from the workshop
                client.DownloadFileAsync(new Uri(self.response.publishedfiledetails[0].file_url, UriKind.Absolute), outputFolder + "download.zip");


                client.Dispose();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets a workshop file using a workshopURI object
        /// </summary>
        /// <param name="workshopURI">Workshop URI needed to get the workshop data</param>
        /// <returns>A workshop file with correct data</returns>
        public static WorkshopFile get(WorkshopURI workshopURI)
        {
            //Base method
            string addr = "http://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/V0001/";

            //Dictionary of method parameters
            Dictionary <string, string> options = new Dictionary <string, string>();

            options.Add("itemcount", "1");
            options.Add("publishedfileids[0]", workshopURI.id);

            //The webrequest
            string web = request.POST(addr, options);

            //Return the workshop file
            WorkshopFile final = new WorkshopFile();

            final.response = JsonConvert.DeserializeObject <WorkshopFile>(web).response;
            return(final); //Done
        }