Пример #1
0
        private void BtnClearAllBackups_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to clear ALL THE BACKUPS\n from UnityStub's cache?", "WARNING", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }


            UnityWatch.currentFileInfo.targetInterface?.RestoreBackup();

            foreach (string file in Directory.GetFiles(Path.Combine(UnityWatch.currentDir, "FILEBACKUPS")))
            {
                try
                {
                    File.Delete(file);
                }
                catch
                {
                    MessageBox.Show($"Could not delete file {file}");
                }
            }

            FileInterface.CompositeFilenameDico = new Dictionary <string, string>();
            UnityWatch.currentFileInfo.targetInterface?.ResetBackup(false);
            FileInterface.SaveCompositeFilenameDico();
            MessageBox.Show("All the backups were cleared.");
        }
Пример #2
0
        public static T Request <T>(String path) where T : class
        {
            LoggerBundle.Debug($"Requested configuration '{path}'");

            if (!File.Exists(path))
            {
                LoggerBundle.Trace($"File '{path}' not found. Trying to create it...");
                FileInterface.Save(Activator.CreateInstance <T>(), path);
                LoggerBundle.Trace($"Successfully created file '{path}'");

                LoggerBundle.Inform(
                    $"Changes to the newly created file '{path}' will take effect after restarting the executable. Adjust default value as needed and restart the application.");
            }

            LoggerBundle.Trace($"Trying to read file '{path}'...");
            (T result, Boolean success) = FileInterface.Read <T>(path);
            if (!success)
            {
                LoggerBundle.Warn(new ProcessAbortedException());
                return(null);
            }

            LoggerBundle.Debug($"Successfully read configuration file '{path}'");
            return(result);
        }
Пример #3
0
 public FileDatabase(FileInterface fileInterface,
                     DefinitionDB definitions,
                     TNGDefinitions tngdefinitions)
 {
     myInterface      = fileInterface;
     myDefinitions    = definitions;
     myTNGDefinitions = tngdefinitions;
     SetInstance(this);
 }
Пример #4
0
        private void BtnResetBackup_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Resetting the backup will take the current rpx and promote it to backup. Do you want to continue?", "Reset Backup", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                CemuWatch.ResetBackup();
            }

            FileInterface.CompositeFilenameDico = new Dictionary <string, string>();
            FileInterface.SaveCompositeFilenameDico();
        }
 int GetSectionHeaderEntryNum(FileInterface elf)
 {
     if (GetElfBitWidth(elf) == 32)
     {
         return(BitConverter.ToUInt16(elf.PeekBytes(0x30, 2).Reverse().ToArray(), 0));
     }
     else //assume it's 64-bit
     {
         return(BitConverter.ToUInt16(elf.PeekBytes(0x3C, 2).Reverse().ToArray(), 0));
     }
 }
 long GetSectionHeaderTableOffset(FileInterface elf)
 {
     if (GetElfBitWidth(elf) == 32)
     {
         return(BitConverter.ToUInt32(elf.PeekBytes(0x20, 4).Reverse().ToArray(), 0));
     }
     else //assume it's 64-bit
     {
         return((long)BitConverter.ToUInt64(elf.PeekBytes(0x28, 8).Reverse().ToArray(), 0));
     }
 }
 bool IsElfBigEndian(FileInterface elf)
 {
     if (elf.PeekByte(0x5) == 0x1)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
 int GetElfBitWidth(FileInterface elf)
 {
     if (elf.PeekByte(0x04) == 0x1)
     {
         return(32);
     }
     if (elf.PeekByte(0x04) == 0x2)
     {
         return(64);
     }
     return(32);
 }
Пример #9
0
        public static BlastLayer GetBlastLayer(string filename)
        {
            string thisSystem = (AllSpec.VanguardSpec[VSPEC.NAME] as string);
            var    rp         = MemoryDomains.GetRomParts(thisSystem, filename);

            IMemoryDomain Corrupt = new FileInterface("File|" + filename, false, false);

            (Corrupt as FileInterface).getMemoryDump(); //gotta cache it otherwise it's going to be super slow

            string[] selectedDomains = (string[])RTCV.NetCore.AllSpec.UISpec["SELECTEDDOMAINS"];

            if (selectedDomains.Length == 0)
            {
                MessageBox.Show("Error: No domain is selected");
                return(null);
            }

            string targetDomain = selectedDomains.FirstOrDefault();

            MemoryDomainProxy[] mdps = (AllSpec.VanguardSpec[VSPEC.MEMORYDOMAINS_INTERFACES] as MemoryDomainProxy[]);

            List <IMemoryDomain> originalDomains = new List <IMemoryDomain>();

            if (rp.Error != null)
            {
                originalDomains.Add(mdps.FirstOrDefault(it => it.Name == targetDomain).MD);

                if (selectedDomains.Length == 0)
                {
                    MessageBox.Show($"Warning: More than one domain was selected. The first one ({targetDomain}) was chosen.");
                }
            }
            else
            {
                originalDomains.Add(mdps.FirstOrDefault(it => it.Name == rp.PrimaryDomain).MD);

                if (rp.SecondDomain != null)
                {
                    originalDomains.Add(mdps.FirstOrDefault(it => it.Name == rp.SecondDomain).MD);
                }
            }

            bool useCustomPrecision = false;

            if (RtcCore.CurrentPrecision != 1)
            {
                var result = MessageBox.Show("Do you want to use Custom Precision for import?", "Use Custom Precision", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                useCustomPrecision = (result == DialogResult.Yes);
            }

            return(GetBlastLayer(originalDomains.ToArray(), Corrupt, rp.SkipBytes, useCustomPrecision));
        }
 long GetProgramSegmentOffset(FileInterface elf, int segment)
 {
     if (GetElfBitWidth(elf) == 32)
     {
         long headeroffset = GetProgramHeaderTableOffset(elf) + (0x20 * Convert.ToInt64(segment));
         return(BitConverter.ToUInt32(elf.PeekBytes(Convert.ToInt64(headeroffset) + 0x04, 4).Reverse().ToArray(), 0));
     }
     else
     {
         long headeroffset = GetProgramHeaderTableOffset(elf) + (0x38 * Convert.ToInt64(segment));
         return((long)BitConverter.ToUInt64(elf.PeekBytes(Convert.ToInt64(headeroffset) + 0x08, 8).Reverse().ToArray(), 0));
     }
 }
 long GetShstrOffset(FileInterface elf)
 {
     if (GetElfBitWidth(elf) == 32)
     {
         int segmentindex = BitConverter.ToUInt16(elf.PeekBytes(0x32, 2).Reverse().ToArray(), 0);
         return(BitConverter.ToUInt32(elf.PeekBytes(GetSectionHeaderTableOffset(elf) + (0x28 * Convert.ToInt64(segmentindex)) + 10, 4).Reverse().ToArray(), 0));
     }
     else
     {
         int segmentindex = BitConverter.ToUInt16(elf.PeekBytes(0x3E, 2).Reverse().ToArray(), 0);
         return((long)BitConverter.ToUInt64(elf.PeekBytes(GetSectionHeaderTableOffset(elf) + (0x40 * Convert.ToInt64(segmentindex)) + 10, 8).Reverse().ToArray(), 0));
     }
 }
 long GetSectionSegmentSize(FileInterface elf, int segment)
 {
     if (GetElfBitWidth(elf) == 32)
     {
         long headeroffset = GetSectionHeaderTableOffset(elf) + (0x28 * Convert.ToInt64(segment));
         return(BitConverter.ToUInt32(elf.PeekBytes(Convert.ToInt64(headeroffset) + 0x14, 4).Reverse().ToArray(), 0));
     }
     else
     {
         long headeroffset = GetSectionHeaderTableOffset(elf) + (0x40 * Convert.ToInt64(segment));
         return((long)BitConverter.ToUInt64(elf.PeekBytes(Convert.ToInt64(headeroffset) + 0x20, 8).Reverse().ToArray(), 0));
     }
 }
Пример #13
0
        public void Main()
        {
            // Invalid path
            string path = ".";

            Assert.Catch <Exception>(() => FileInterface.readFromFile(path));

            // Incorrect number of characters
            path = Constants.TEST_INPUT + @"\wrong_num_chars.txt";
            Assert.Catch <Exception>(() => FileInterface.readFromFile(path));

            // Working file
            path = Constants.TEST_INPUT + @"\working_file.txt";
            Board board = FileInterface.readFromFile(path);
            List <List <char> > expected = new List <List <char> >
            {
                new List <char> {
                    '2', '-', '3', '1'
                },
                new List <char> {
                    '1', '3', '-', '4'
                },
                new List <char> {
                    '3', '1', '4', '-'
                },
                new List <char> {
                    '-', '2', '1', '3'
                }
            };

            Assert.IsTrue(TestUtils.boardsEqual(expected, board.board));
            Board copied = new Board(4, new CharSet(new List <char> {
                '1', '2', '3', '4'
            }), expected);

            Assert.IsTrue(TestUtils.boardsEqual(expected, copied.board));

            // Copy constructor
            Board otherBoard = new Board(board);

            Assert.IsTrue(TestUtils.boardsEqual(otherBoard.board, board.board));

            Assert.Catch <Exception>(() => board.setCell(100, 100, '1'));
            Assert.Catch <Exception>(() => board.setCell(0, 0, '0'));

            Assert.IsTrue(board.isValidChar('-'));
            Assert.IsTrue(board.isValidChar('1'));
            Assert.IsFalse(board.isValidChar('5'));

            board.printBoard();
        }
        public ELFHelper(FileInterface elfInterface)
        {
            string elfpath = elfInterface.Filename;

            pathtoelf = elfpath;
            if (elfpath.Contains("rpx"))
            {
                IsRPX = true;
            }
            else
            {
                IsRPX = false;
            }
            var elfpathInfo = new FileInfo(elfpath);

            bitwidth  = GetElfBitWidth(elfInterface);
            BigEndian = IsElfBigEndian(elfInterface);
            if (!IsRPX) //RPXs are ELF files but don't have program headers.
            {
                pht_offset  = GetProgramHeaderTableOffset(elfInterface);
                pht_entries = GetProgramHeaderEntryNum(elfInterface);
                ps_offsets  = new long[pht_entries];
                ps_sizes    = new long[pht_entries];
            }
            sht_offset  = GetSectionHeaderTableOffset(elfInterface);
            sht_entries = GetSectionHeaderEntryNum(elfInterface);
            ss_names    = new string[sht_entries];
            ss_offsets  = new long[sht_entries];
            ss_sizes    = new long[sht_entries];
            if (!IsRPX)
            {
                int ph_iterator = 0;
                while (ph_iterator < pht_entries)
                {
                    ph_iterator++;
                    ps_offsets[ph_iterator] = GetProgramSegmentOffset(elfInterface, ph_iterator);
                    ps_sizes[ph_iterator]   = GetProgramSegmentSize(elfInterface, ph_iterator);
                }
            }
            int sh_iterator = 0;

            while (sh_iterator < sht_entries)
            {
                sh_iterator++;
                ss_names[sh_iterator]   = GetSectionSegmentName(elfInterface, sh_iterator);
                ss_offsets[sh_iterator] = GetSectionSegmentOffset(elfInterface, sh_iterator);
                ss_sizes[sh_iterator]   = GetSectionSegmentSize(elfInterface, sh_iterator);
            }
        }
        public static void Start()
        {
            RTCV.Common.Logging.StartLogging(VanguardCore.logPath);
            if (VanguardCore.vanguardConnected)
            {
                RemoveDomains();
            }

            //FileWatch.currentFileInfo = new FileStubFileInfo();

            DisableInterface();
            //state = TargetType.UNFOUND;

            RtcCore.EmuDirOverride = true; //allows the use of this value before vanguard is connected


            string backupPath = Path.Combine(FileWatch.currentDir, "FILEBACKUPS");
            string paramsPath = Path.Combine(FileWatch.currentDir, "PARAMS");

            if (!Directory.Exists(backupPath))
            {
                Directory.CreateDirectory(backupPath);
            }

            if (!Directory.Exists(paramsPath))
            {
                Directory.CreateDirectory(paramsPath);
            }

            string disclaimerPath     = Path.Combine(currentDir, "LICENSES", "DISCLAIMER.TXT");
            string disclaimerReadPath = Path.Combine(currentDir, "PARAMS", "DISCLAIMERREAD");

            if (File.Exists(disclaimerPath) && !File.Exists(disclaimerReadPath))
            {
                MessageBox.Show(File.ReadAllText(disclaimerPath).Replace("[ver]", FileWatch.FileStubVersion), "File Stub", MessageBoxButtons.OK, MessageBoxIcon.Information);
                File.Create(disclaimerReadPath);
            }

            //If we can't load the dictionary, quit the wgh to prevent the loss of backups
            if (!FileInterface.LoadCompositeFilenameDico(FileWatch.currentDir))
            {
                Application.Exit();
            }
        }
 string GetSectionSegmentName(FileInterface elf, int segment)
 {
     if (GetElfBitWidth(elf) == 32)
     {
         long headeroffset = GetSectionHeaderTableOffset(elf) + (0x28 * Convert.ToInt64(segment));
         long stroffset    = BitConverter.ToUInt32(elf.PeekBytes(headeroffset, 4).Reverse().ToArray(), 0);
         if (GetShstrOffset(elf) == 0)
         {
             return(" ");
         }
         return(System.Text.Encoding.ASCII.GetString(elf.PeekBytes(GetShstrOffset(elf) + stroffset, 8)));
     }
     else
     {
         long headeroffset = GetSectionHeaderTableOffset(elf) + (0x40 * Convert.ToInt64(segment));
         long stroffset    = (long)BitConverter.ToUInt64(elf.PeekBytes(headeroffset, 8).Reverse().ToArray(), 0);
         if (GetShstrOffset(elf) == 0)
         {
             return(" ");
         }
         return(System.Text.Encoding.ASCII.GetString(elf.PeekBytes(GetShstrOffset(elf) + stroffset, 8)));
     }
 }
Пример #17
0
        public void Main()
        {
            string path = Constants.EASY_INPUT;

            string[] inputFiles = Directory.GetFiles(path);
            foreach (string file in inputFiles)
            {
                Board board;
                try
                {
                    board = FileInterface.readFromFile(file);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }

                Tracker tracker = new Tracker(board);
                Solver  solver  = new Solver(tracker);
                tracker = solver.run();

                if (!tracker.valid)
                {
                    Assert.IsFalse(TestUtils.isCorrectSolution(tracker.board));
                }
                else
                {
                    if (tracker.solutionCnt > 1)
                    {
                        Console.WriteLine("WARNING: More than one solution found. One is shown.");
                    }
                    Assert.IsTrue(TestUtils.isCorrectSolution(tracker.board),
                                  "ERROR: Could not find correct solution for file " + file + ".");
                }
            }
        }
Пример #18
0
        public static bool FileToPDF(FileInterface file, string outputPath)
        {
            try
            {
                if (ArquivoAberto(file.file.FullName))
                {
                    DialogResult closed;
                    do
                    {
                        closed = MessageBox.Show(String.Format("O arquivo {0} não pode ser convertido pois está sendo " +
                                                               "usado por outro processo neste momento. Por favor, feche o arquivo " +
                                                               "e clique em 'Sim' se deseja continuar. Para cancelar a conversão deste arquivo, clique em 'Não'.", file.file.Name), "Erro - Arquivo aberto", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (!ArquivoAberto(file.file.FullName))
                        {
                            break;
                        }
                    }while (closed.Equals(DialogResult.Yes));
                    if (closed.Equals(DialogResult.No))
                    {
                        Arquivo arquivo = new Arquivo(file.file.Name, file.file.Extension, "Cancelado", "Conversão cancelada pelo usuário");
                        Arquivos.Add(arquivo);
                        return(false);
                    }
                }
                if (file.file.Extension.Contains("doc"))
                {
                    string wordDoc = file.file.FullName;
                    string output  = RetornarOutputCorreto(outputPath, file.file.Name.Replace(file.file.Extension, ""));
                    Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();

                    wordDocument = appWord.Documents.Open(wordDoc);
                    wordDocument.ExportAsFixedFormat(output, WdExportFormat.wdExportFormatPDF);

                    object saveOption     = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
                    object originalFormat = Microsoft.Office.Interop.Word.WdOriginalFormat.wdWordDocument;
                    object routeDocument  = false;

                    appWord.Quit(ref saveOption, ref originalFormat, ref routeDocument);
                    Arquivo arquivo = new Arquivo(file.file.Name, file.file.Extension, "Convertido", "Arquivo convertido com sucesso!");
                    Arquivos.Add(arquivo);
                    return(true);
                }
                else
                {
                    Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application();
                    Microsoft.Office.Interop.Excel.Workbook    excelWorkBook    = null;

                    string paramSourceBookPath = file.file.FullName;
                    object paramMissing        = Type.Missing;
                    //string paramExportFilePath = outputPath + String.Format(@"\{0}.pdf", file.file.Name.Replace(file.file.Extension, ""));
                    string               paramExportFilePath = RetornarOutputCorreto(outputPath, file.file.Name.Replace(file.file.Extension, ""));
                    XlFixedFormatType    paramExportFormat   = XlFixedFormatType.xlTypePDF;
                    XlFixedFormatQuality paramExportQuality  = XlFixedFormatQuality.xlQualityStandard;
                    bool   paramOpenAfterPublish             = false;
                    bool   paramIncludeDocProps  = true;
                    bool   paramIgnorePrintAreas = true;
                    object paramFromPage         = Type.Missing;
                    object paramToPage           = Type.Missing;

                    excelWorkBook = excelApplication.Workbooks.Open(paramSourceBookPath,
                                                                    paramMissing, paramMissing, paramMissing, paramMissing,
                                                                    paramMissing, paramMissing, paramMissing, paramMissing,
                                                                    paramMissing, paramMissing, paramMissing, paramMissing,
                                                                    paramMissing, paramMissing);

                    if (excelWorkBook != null)
                    {
                        excelWorkBook.ExportAsFixedFormat(paramExportFormat,
                                                          paramExportFilePath, paramExportQuality,
                                                          paramIncludeDocProps, paramIgnorePrintAreas, paramFromPage,
                                                          paramToPage, paramOpenAfterPublish,
                                                          paramMissing);
                    }

                    if (excelWorkBook != null)
                    {
                        excelWorkBook.Close(false, paramMissing, paramMissing);
                        excelWorkBook = null;
                    }

                    if (excelApplication != null)
                    {
                        excelApplication.Quit();
                        excelApplication = null;
                    }
                    Arquivo arquivo = new Arquivo(file.file.Name, file.file.Extension, "Convertido", "Arquivo convertido com sucesso!");
                    Arquivos.Add(arquivo);
                    return(true);
                }
            }
            catch (Exception erro)
            {
                Arquivo arquivo = new Arquivo(file.file.Name, file.file.Extension, "Erro", erro.Message);
                Arquivos.Add(arquivo);
                return(false);
            }
        }
Пример #19
0
        void sync()
        {
            while (paused || tempSyncItems_locked)
            {
                ;
            }

            if (tempSyncItems.Count > 0)
            {
                tempSyncItems_locked = true;

                lockedSynchronizingItems.Clear();
                lockedSynchronizingItems.AddRange(tempSyncItems);
                tempSyncItems.Clear();

                tempSyncItems_locked = false;
            }


            foreach (var syncItem in lockedSynchronizingItems)
            {
                while (paused)
                {
                    ;
                }

                var item  = syncItem.GetItem();
                var isDir = item.IsFolder();

                string finalPath = PathNormalizer.Normalize(
                    Path.Combine(folder, item.GetFullName())
                    );

                if (isDir)
                {
                    if (!Directory.Exists(finalPath))
                    {
                        Log("DOWNLOAD", item.GetFullName(), true);
                        Directory.CreateDirectory(finalPath);
                    }

                    // Else does nothing, directory already exists
                    syncItem.State = SynchronizingItem.SyncState.Downloading;
                    syncItem.Task  = SynchronizingItem.TaskState.Done;
                }
                else
                {
                    FileInterface file = new FileInterface(item);

                    DownloadOrUpload downOrUp;
                    if (syncItem.State == SynchronizingItem.SyncState.Uploading)
                    {
                        downOrUp = DownloadOrUpload.Upload;
                    }
                    else if (syncItem.State == SynchronizingItem.SyncState.Downloading)
                    {
                        downOrUp = DownloadOrUpload.Download;
                    }
                    else
                    {
                        downOrUp = CheckDownloadOrUpload(folder, item);
                    }

                    if (downOrUp == DownloadOrUpload.Nothing)
                    {
                        syncItem.State = SynchronizingItem.SyncState.None;
                    }
                    else if (downOrUp == DownloadOrUpload.Download)
                    {
                        Log("DOWNLOAD", finalPath, false);

                        syncItem.State = SynchronizingItem.SyncState.Downloading;
                        syncItem.Task  = SynchronizingItem.TaskState.Executing;
                        localStack.UpdateState(syncItem);

                        file.DownloadTo(finalPath);
                    }
                    else if (downOrUp == DownloadOrUpload.Update)
                    {
                        Log("UPLOAD", finalPath, false);

                        syncItem.State = SynchronizingItem.SyncState.Uploading;
                        syncItem.Task  = SynchronizingItem.TaskState.Executing;
                        localStack.UpdateState(syncItem);

                        file.UpdateFrom(finalPath);
                    }
                }

                syncItem.Task = SynchronizingItem.TaskState.Done;
                localStack.UpdateState(syncItem);
            }
        }
        internal static bool LoadTarget()
        {
            if (currentFileInfo.selectedTargetType == TargetType.SINGLE_FILE)
            {
                FileInterface.identity = FileInterfaceIdentity.SELF_DESCRIBE;

                string filename = Path.Combine(FileWatch.currentDir, "DOSBOX", "save", "1", "Memory");

                if (!File.Exists(filename))
                {
                    MessageBox.Show($"Could not find part of the path {filename}\n\nMake sure you have created your savestate with the button in this interface\n\nIf you changed the Save State slot, put it back to 1.");
                    return(false);
                }

                /*
                 * OpenFileDialog OpenFileDialog1;
                 * OpenFileDialog1 = new OpenFileDialog();
                 *
                 * OpenFileDialog1.Title = "Open File";
                 * OpenFileDialog1.Filter = "files|*.*";
                 * OpenFileDialog1.RestoreDirectory = true;
                 * if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
                 * {
                 *  if (OpenFileDialog1.FileName.ToString().Contains('^'))
                 *  {
                 *      MessageBox.Show("You can't use a file that contains the character ^ ");
                 *      return false;
                 *  }
                 *
                 *  filename = OpenFileDialog1.FileName;
                 * }
                 * else
                 *  return false;
                 */

                string targetId = "File|" + filename;

                CloseTarget(false);


                FileInterface fi = null;

                Action <object, EventArgs> action = (ob, ea) =>
                {
                    fi = new FileInterface(targetId, FileWatch.currentFileInfo.bigEndian, true);

                    if (FileWatch.currentFileInfo.useCacheAndMultithread)
                    {
                        fi.getMemoryDump();
                    }
                };

                Action <object, EventArgs> postAction = (ob, ea) =>
                {
                    if (fi == null || fi.lastMemorySize == null)
                    {
                        MessageBox.Show("Failed to load target");
                        S.GET <StubForm>().DisableTargetInterface();
                        return;
                    }

                    FileWatch.currentFileInfo.targetShortName = fi.ShortFilename;
                    FileWatch.currentFileInfo.targetFullName  = fi.Filename;

                    FileWatch.currentFileInfo.targetInterface = fi;
                    S.GET <StubForm>().lbTarget.Text          = targetId + "|MemorySize:" + fi.lastMemorySize.ToString();

                    if (VanguardCore.vanguardConnected)
                    {
                        UpdateDomains();
                    }

                    //Refresh the UI
                    //RefreshUIPostLoad();
                };

                S.GET <StubForm>().RunProgressBar($"Loading target...", 0, action, postAction);
            }
            else //MULTIPLE_FILE
            {
                switch (currentFileInfo.selectedTargetType)
                {
                case TargetType.MULTIPLE_FILE_SINGLEDOMAIN:
                    FileInterface.identity = FileInterfaceIdentity.SELF_DESCRIBE;
                    break;

                case TargetType.MULTIPLE_FILE_MULTIDOMAIN:
                    FileInterface.identity = FileInterfaceIdentity.HASHED_PREFIX;
                    break;

                case TargetType.MULTIPLE_FILE_MULTIDOMAIN_FULLPATH:
                    FileInterface.identity = FileInterfaceIdentity.FULL_PATH;
                    break;
                }


                S.GET <SelectMultipleForm>().Close();
                var smForm = new SelectMultipleForm();
                S.SET(smForm);

                if (smForm.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }


                var mfi = (MultipleFileInterface)FileWatch.currentFileInfo.targetInterface;
                //currentTargetName = mfi.ShortFilename;
                S.GET <StubForm>().lbTarget.Text     = mfi.ShortFilename + "|MemorySize:" + mfi.lastMemorySize.ToString();
                StockpileManager_EmuSide.UnCorruptBL = null;
            }

            return(true);
        }
Пример #21
0
        public void Main()
        {
            Assert.Catch(() => FileInterface.readFromFile("."));

            string path = Constants.TEST_INPUT + @"\file_too_short.txt";

            Assert.Catch(() => FileInterface.readFromFile(path));

            path = Constants.TEST_INPUT + @"\not_enough_lines.txt";
            Assert.Catch(() => FileInterface.readFromFile(path));

            path = Constants.TEST_INPUT + @"\long_characters.txt";
            Assert.Catch(() => FileInterface.readFromFile(path));

            path = Constants.TEST_INPUT + @"\duplicate_chars.txt";
            Assert.Catch(() => FileInterface.readFromFile(path));

            path = Constants.TEST_INPUT + @"\incorrect_line.txt";
            Assert.Catch(() => FileInterface.readFromFile(path));

            // Working file
            path = Constants.TEST_INPUT + @"\working_file.txt";
            Board board = FileInterface.readFromFile(path);
            List <List <char> > expected = new List <List <char> >
            {
                new List <char> {
                    '2', '-', '3', '1'
                },
                new List <char> {
                    '1', '3', '-', '4'
                },
                new List <char> {
                    '3', '1', '4', '-'
                },
                new List <char> {
                    '-', '2', '1', '3'
                }
            };

            Assert.True(TestUtils.boardsEqual(expected, board.board));

            long micros = 1294829015890289018;

            Assert.AreEqual(FileInterface.getTimeString(micros), "26:38:10.289018");

            Tracker tracker = new Tracker(board);
            Solver  solver  = new Solver(tracker);

            FileInterface.writeToFile(board, board, solver, 23087);

            List <string> expectedLines = new List <string>
            {
                "2 - 3 1",
                "1 3 - 4",
                "3 1 4 -",
                "- 2 1 3"
            };
            var lines = FileInterface.getBoardFileLines(board);

            for (int i = 0; i < 4; ++i)
            {
                Assert.AreEqual(lines[i], expectedLines[i]);
            }

            List <char> lc = new List <char> {
                'a', 'b'
            };

            Assert.AreEqual(FileInterface.lineToString(lc), "a b");
        }
Пример #22
0
        internal static bool LoadTargets(FileTarget[] provided = null)
        {
            FileTarget[] targets;
            string       requestedFileType = currentSession.selectedTargetType;

            if (provided == null)
            {
                var lbTargets = S.GET <StubForm>().lbTargets;
                if (lbTargets.Items.Count == 0)
                {
                    MessageBox.Show("No targets scheduled for loading. Aborting loading.");
                    return(false);
                }

                targets = lbTargets.Items.Cast <FileTarget>().ToArray();
            }
            else
            {
                targets = provided;
            }

            if (requestedFileType == TargetType.SINGLE_FILE)
            {
                FileInterface.identity = FileInterfaceIdentity.SELF_DESCRIBE;

                var    target   = targets[0];
                string filename = targets[0].ToString();

                target.BigEndian = FileWatch.currentSession.bigEndian;

                CloseActiveTargets(false);

                FileInterface fi = null;

                Action <object, EventArgs> action = (ob, ea) =>
                {
                    fi = new FileInterface(target);

                    if (FileWatch.currentSession.useCacheAndMultithread)
                    {
                        fi.getMemoryDump();
                    }
                };

                Action <object, EventArgs> postAction = (ob, ea) =>
                {
                    if (fi == null || fi.lastMemorySize == null)
                    {
                        MessageBox.Show("Failed to load target");
                        S.GET <StubForm>().DisableTargetInterface();
                        return;
                    }

                    FileWatch.currentSession.targetShortName = fi.ShortFilename;
                    FileWatch.currentSession.targetFullName  = fi.Filename;

                    FileWatch.currentSession.fileInterface = fi;
                    S.GET <StubForm>().lbTarget.Text       = fi.GetType().ToString() + "|MemorySize:" + fi.lastMemorySize.ToString();

                    if (VanguardCore.vanguardConnected)
                    {
                        UpdateDomains();
                    }

                    //Refresh the UI
                    //RefreshUIPostLoad();
                };

                S.GET <StubForm>().RunProgressBar($"Loading target...", 0, action, postAction);
            }
            else //MULTIPLE_FILE
            {
                switch (currentSession.selectedTargetType)
                {
                case TargetType.MULTIPLE_FILE_SINGLEDOMAIN:
                    FileInterface.identity = FileInterfaceIdentity.SELF_DESCRIBE;
                    break;

                case TargetType.MULTIPLE_FILE_MULTIDOMAIN:
                default:
                    FileInterface.identity = FileInterfaceIdentity.HASHED_PREFIX;
                    break;

                case TargetType.MULTIPLE_FILE_MULTIDOMAIN_FULLPATH:
                    FileInterface.identity = FileInterfaceIdentity.FULL_PATH;
                    break;
                }


                foreach (var target in targets)
                {
                    target.BigEndian = FileWatch.currentSession.bigEndian;
                }

                var mfi = new MultipleFileInterface(targets, FileWatch.currentSession.bigEndian, FileWatch.currentSession.useAutomaticBackups);

                if (FileWatch.currentSession.useCacheAndMultithread)
                {
                    mfi.getMemoryDump();
                }

                FileWatch.currentSession.fileInterface = mfi;

                if (VanguardCore.vanguardConnected)
                {
                    FileWatch.UpdateDomains();
                }

                S.GET <StubForm>().lbTarget.Text    = mfi.ShortFilename + "|MemorySize:" + mfi.lastMemorySize.ToString();
                StockpileManagerEmuSide.UnCorruptBL = null;
            }

            return(true);
        }
Пример #23
0
        public static void LoadTarget()
        {
            if (WGH_Core.ghForm.rbTargetFile.Checked)
            {
                OpenFileDialog OpenFileDialog1;
                OpenFileDialog1 = new OpenFileDialog();

                OpenFileDialog1.Title            = "Open File";
                OpenFileDialog1.Filter           = "files|*.*";
                OpenFileDialog1.RestoreDirectory = true;
                if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if (OpenFileDialog1.FileName.ToString().Contains('^'))
                    {
                        MessageBox.Show("You can't use a file that contains the character ^ ");
                        return;
                    }

                    currentTargetId       = "File|" + OpenFileDialog1.FileName.ToString();
                    currentTargetFullName = OpenFileDialog1.FileName.ToString();
                }
                else
                {
                    return;
                }

                //Disable caching of the previously loaded file if it was enabled
                if (ghForm.btnEnableCaching.Text == "Disable caching on current target")
                {
                    ghForm.btnEnableCaching.PerformClick();
                }

                if (currentMemoryInterface != null && (currentTargetType == "Dolphin" || currentTargetType == "File" || currentTargetType == "MultipleFiles"))
                {
                    WGH_Core.RestoreTarget();
                    currentMemoryInterface.stream?.Dispose();
                }

                currentTargetType = "File";
                var fi = new FileInterface(currentTargetId);
                currentTargetName = fi.ShortFilename;

                currentMemoryInterface = fi;
                ghForm.lbTarget.Text   = currentTargetId + "|MemorySize:" + fi.lastMemorySize.ToString();
            }
            else if (WGH_Core.ghForm.rbTargetMultipleFiles.Checked)
            {
                if (smForm != null)
                {
                    smForm.Close();
                }

                smForm = new WGH_SelectMultipleForm();

                if (smForm.ShowDialog() != DialogResult.OK)
                {
                    WGH_Core.currentMemoryInterface = null;
                    return;
                }

                currentTargetType = "MultipleFiles";
                var mfi = (MultipleFileInterface)WGH_Core.currentMemoryInterface;
                currentTargetName    = mfi.ShortFilename;
                ghForm.lbTarget.Text = mfi.ShortFilename + "|MemorySize:" + mfi.lastMemorySize.ToString();
            }
            else if (WGH_Core.ghForm.rbTargetProcess.Checked)
            {
                if (hpForm != null)
                {
                    hpForm.Close();
                }

                hpForm = new WGH_HookProcessForm();

                if (hpForm.ShowDialog() != DialogResult.OK)
                {
                    WGH_Core.currentMemoryInterface = null;
                    return;
                }

                currentTargetType = "Process";
                var mfi = (ProcessInterface)WGH_Core.currentMemoryInterface;
                currentTargetName    = mfi.ProcessName;
                ghForm.lbTarget.Text = mfi.ProcessName + "|MemorySize:" + mfi.lastMemorySize.ToString();
            }
            if (WGH_Core.ghForm.rbTargetDolphin.Checked)
            {
                OpenFileDialog OpenFileDialog1;
                OpenFileDialog1 = new OpenFileDialog();

                OpenFileDialog1.Title            = "Open File";
                OpenFileDialog1.Filter           = "Dolphin Savestates|*.state;*.s01;*.s02;*.s03;*.s04;*.s05;*.s06;*.s07;*.s08;*.s09;*.sav|All Files|*.*";
                OpenFileDialog1.RestoreDirectory = true;
                if (OpenFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if (OpenFileDialog1.FileName.ToString().Contains('^'))
                    {
                        MessageBox.Show("You can't use a file that contains the character ^ ");
                    }

                    currentTargetId       = "Dolphin|" + OpenFileDialog1.FileName.ToString();
                    currentTargetFullName = OpenFileDialog1.FileName.ToString();
                }
                else
                {
                    return;
                }

                //Disable caching of the previously loaded file if it was enabled
                if (ghForm.btnEnableCaching.Text == "Disable caching on current target")
                {
                    ghForm.btnEnableCaching.PerformClick();
                }

                if (currentMemoryInterface != null && (currentTargetType == "Dolphin" || currentTargetType == "File" || currentTargetType == "MultipleFiles"))
                {
                    WGH_Core.RestoreTarget();
                    currentMemoryInterface.stream?.Dispose();
                }


                currentTargetType = "Dolphin";
                var di = new DolphinInterface(currentTargetId);
                currentTargetName = di.ShortFilename;

                currentMemoryInterface  = di;
                ghForm.lbTarget.Text    = currentTargetId + "|MemorySize:" + di.lastMemorySize.ToString();
                currentDolphinSavestate = di.getCorruptFilename();

                //Cache the new file
                ghForm.btnEnableCaching.PerformClick();

                //Update the savestate info.
                if (WGH_Core.ssForm != null)
                {
                    WGH_Core.ssForm.GetSavestateInfo();
                }
            }

            /*
             * else if (WGH_Core.ghForm.rbTargetDolphin.Checked)
             * {
             *
             *  currentTargetType = "Dolphin";
             *  //var mfi = (DolphinInterface)WGH_Core.currentMemoryInterface;
             *  WGH_Core.currentMemoryInterface = new DolphinInterface("Test");
             *  currentTargetName = "Dolphin";
             *  ghForm.lbTarget.Text = currentTargetName + "|MemorySize:" + WGH_Core.currentMemoryInterface.lastMemorySize.ToString();
             * }*/
        }
Пример #24
0
        internal static bool LoadTarget()
        {
            FileInterface.identity = FileInterfaceIdentity.SELF_DESCRIBE;



            if (!File.Exists(DosboxSavestateWorkMemoryFile))
            {
                MessageBox.Show($"Could not find part of the path {DosboxSavestateWorkMemoryFile}\n\nMake sure you have created your savestate with the button in this interface\n\nIf you changed the Save State slot, put it back to 1.");
                return(false);
            }


            string targetId = "File|" + DosboxSavestateWorkMemoryFile;

            CloseTarget(false);


            FileInterface fi = null;



            Action <object, EventArgs> action = (ob, ea) =>
            {
                fi = new FileInterface(targetId, FileWatch.currentFileInfo.bigEndian, true, startPadding: UNCOMPRESSED_MEMORY_OFFSET);

                if (FileWatch.currentFileInfo.useCacheAndMultithread)
                {
                    fi.getMemoryDump();
                }
            };

            Action <object, EventArgs> postAction = (ob, ea) =>
            {
                if (fi == null || fi.lastMemorySize == null)
                {
                    MessageBox.Show("Failed to load target");
                    S.GET <StubForm>().DisableTargetInterface();
                    return;
                }

                FileWatch.currentFileInfo.targetShortName = fi.ShortFilename;
                FileWatch.currentFileInfo.targetFullName  = fi.Filename;

                FileWatch.currentFileInfo.targetInterface = fi;
                S.GET <StubForm>().lbTarget.Text          = targetId + "|MemorySize:" + fi.lastMemorySize.ToString();

                if (VanguardCore.vanguardConnected)
                {
                    UpdateDomains();
                }

                //Refresh the UI
                //RefreshUIPostLoad();
            };

            S.GET <StubForm>().RunProgressBar($"Loading target...", 0, action, postAction);


            return(true);
        }