Exemple #1
0
        public ModDatabaseModViewModel(ModDatabaseMod mod, ModDatabase database)
        {
            this.mod       = mod;
            this.timer     = new Timer();
            this.database  = database;
            this.saver     = new DownloadedModSaver();
            this.extractor = new ModExtracter();

            DownloadModCommand = new Command(DownloadMod, x => !IsDownloading);

            timer.AutoReset = false;
            timer.Elapsed  += (o, e) =>
            {
                ModHasBeenDownloaded = false;
                timer.Stop();
            };
            timer.Interval = TimeSpan.FromSeconds(5).TotalMilliseconds;
        }
Exemple #2
0
        public FileInfo Save(ModDatabaseMod mod, byte[] fileData)
        {
            AssertTempDirectoryExists();

            var fileName = Regex.Replace(mod.Title.Replace(' ', '_'), "[^a-zA-Z0-9]", "") + ".downloaded";
            var filePath = Path.Combine(TempDirectory, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            using (var stream = File.Create(filePath))
            {
                var writer = new BinaryWriter(stream);
                writer.Write(fileData);
            }

            return(new FileInfo(filePath));
        }