Esempio n. 1
0
 public static async Task FindExistingSavestatesForNewROM(ROMDBEntry entry)
 {
     ROMDatabase db = ROMDatabase.Current;
     StorageFolder localFolder = ApplicationData.Current.LocalFolder;
     StorageFolder romFolder = await localFolder.GetFolderAsync(ROM_DIRECTORY);
     StorageFolder saveFolder = await romFolder.GetFolderAsync(SAVE_DIRECTORY);
     IReadOnlyList<StorageFile> saves = await saveFolder.GetFilesAsync();
     // Savestates zuordnen
     foreach (var save in saves)
     {
         if (save.Name.Substring(0, save.Name.Length - 2).Equals(entry.DisplayName + ".0"))
         {
             // Savestate gehoert zu ROM
             String number = save.Name.Substring(save.Name.Length - 2);
             int slot = int.Parse(number);
             SavestateEntry ssEntry = new SavestateEntry()
             {
                 ROM = entry,
                 Savetime = save.DateCreated.DateTime,
                 Slot = slot,
                 FileName = save.Name
             };
             db.Add(ssEntry);
         }
     }
 }
 public void Add(SavestateEntry entry)
 {
     if (!context.DatabaseExists())
     {
         throw new InvalidOperationException("Database does not exist.");
     }
     context.SavestateTable.InsertOnSubmit(entry);
     context.SubmitChanges();
 }
        public bool RemoveSavestateFromDB(SavestateEntry entry)
        {
            try
            {
                entry.ROM.Savestates.Remove(entry);
                this.context.SavestateTable.DeleteOnSubmit(entry);
                this.context.SubmitChanges();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
        public int GetLastSavestateSlotByFileNameExceptAuto(string filename)
        {
            if (!context.DatabaseExists())
            {
                throw new InvalidOperationException("Database does not exist.");
            }
            filename = filename.ToLower();
            SavestateEntry save = this.context.SavestateTable
                                  .Where(s => s.ROMFileName.ToLower().Equals(filename) && s.Slot != 10)
                                  .OrderByDescending(s => s.Savetime)
                                  .FirstOrDefault();

            if (save != null)
            {
                return(save.Slot);
            }
            return(0);
        }
Esempio n. 5
0
        private async Task DownloadFile(SkyDriveListItem item, LiveConnectClient client)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            StorageFolder romFolder = await folder.CreateFolderAsync(FileHandler.ROM_DIRECTORY, CreationCollisionOption.OpenIfExists);
            StorageFolder saveFolder = await romFolder.CreateFolderAsync(FileHandler.SAVE_DIRECTORY, CreationCollisionOption.OpenIfExists);

            String path = romFolder.Path;
            String savePath = saveFolder.Path;

            ROMDatabase db = ROMDatabase.Current;
            var indicator = new ProgressIndicator()
            {
                IsIndeterminate = true,
                IsVisible = true,
                Text = String.Format(AppResources.DownloadingProgressText, item.Name)
            };

            SystemTray.SetProgressIndicator(this, indicator);

            LiveDownloadOperationResult e = await client.DownloadAsync(item.SkyDriveID + "/content");
            if (e != null)
            {
                byte[] tmpBuf = new byte[e.Stream.Length];
                StorageFile destinationFile = await saveFolder.CreateFileAsync(item.Name, CreationCollisionOption.ReplaceExisting);
                using (IRandomAccessStream destStream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
                using (DataWriter writer = new DataWriter(destStream))
                {
                    while (e.Stream.Read(tmpBuf, 0, tmpBuf.Length) != 0)
                    {
                        writer.WriteBytes(tmpBuf);
                    }
                    await writer.StoreAsync();
                    await writer.FlushAsync();
                    writer.DetachStream();
                }
                e.Stream.Close();
                item.Downloading = false;
                SystemTray.GetProgressIndicator(this).IsVisible = false;

                if (item.Type == SkyDriveItemType.Savestate)
                {
                    if (!db.SavestateEntryExisting(item.Name))
                    {
                        String number = item.Name.Substring(item.Name.Length - 2);
                        int slot = int.Parse(number);
                        ROMDBEntry entry = db.GetROMFromSavestateName(item.Name);
                        // Null = No ROM existing for this file -> skip inserting into database. The file will be inserted when the corresponding ROM is downloaded.
                        if (entry != null)
                        {
                            SavestateEntry ssEntry = new SavestateEntry()
                            {
                                ROM = entry,
                                Savetime = DateTime.Now,
                                Slot = slot,
                                FileName = item.Name
                            };
                            db.Add(ssEntry);
                            db.CommitChanges();
                        }
                    }
                }

                MessageBox.Show(String.Format(AppResources.DownloadCompleteText, item.Name));
            }
            else
            {
                SystemTray.GetProgressIndicator(this).IsVisible = false;
                MessageBox.Show(String.Format(AppResources.DownloadErrorText, item.Name, "Api error"), AppResources.ErrorCaption, MessageBoxButton.OK);
            }
        }
Esempio n. 6
0
        public static async Task<bool> DeleteSaveState(SavestateEntry entry)
        {
            ROMDatabase db = ROMDatabase.Current;
            if (!db.RemoveSavestateFromDB(entry))
            {
                return false;
            }

            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFolder romFolder = await localFolder.GetFolderAsync(ROM_DIRECTORY);
            StorageFolder saveFolder = await romFolder.GetFolderAsync(SAVE_DIRECTORY);

            try
            {
                StorageFile file = await saveFolder.GetFileAsync(entry.FileName);
                await file.DeleteAsync();
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Esempio n. 7
0
 private static void createSavestate(int slot, string romFileName)
 {
     ROMDatabase db = ROMDatabase.Current;
     string saveFileName = romFileName.Substring(0, romFileName.Length - 3);
     if (slot < 10)
     {
         saveFileName += "00" + slot;
     }
     else
     {
         saveFileName += "0" + slot;
     }
     SavestateEntry entry;
     if ((entry = db.GetSavestate(romFileName, slot)) == null)
     {
         ROMDBEntry rom = db.GetROM(romFileName);
         entry = new SavestateEntry()
         {
             ROM = rom,
             FileName = saveFileName,
             ROMFileName = romFileName,
             Savetime = DateTime.Now,
             Slot = slot
         };
         db.Add(entry);
     }
     else
     {
         entry.Savetime = DateTime.Now;
     }
     db.CommitChanges();
 }
Esempio n. 8
0
        public bool RemoveSavestateFromDB(SavestateEntry entry)
        {
            try
            {
                entry.ROM.Savestates.Remove(entry);
                this.context.SavestateTable.DeleteOnSubmit(entry);
                this.context.SubmitChanges();
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Esempio n. 9
0
 public void Add(SavestateEntry entry)
 {
     if (!context.DatabaseExists())
     {
         throw new InvalidOperationException("Database does not exist.");
     }
     context.SavestateTable.InsertOnSubmit(entry);
     context.SubmitChanges();
 }