示例#1
0
        private void mButtonNext_Click(object sender, EventArgs e)
        {
            try
            {
                VolumeSource source  = CreateSource();
                BaseArchive  archive = CreateArchive();

                string vidFilename = mObject.StoragePath + PWLib.Platform.Windows.Path.DirectorySeparatorChar + mObject.Name + ".vol";

                VolumeDescriptor vdesc = VolumeDescriptorList.Instance.AddNewDescriptor(mObject.Name, vidFilename, source, archive);
                if (mObject.RevisionsToKeep > 0)
                {
                    vdesc.RevisionsToKeep = mObject.RevisionsToKeep;
                }
                else
                {
                    vdesc.TimePeriodToMonitor = mObject.TimePeriodToKeep;
                }

                if (mStartBackupNow.Checked)
                {
                    Log.WriteLine(LogType.TextLogVerbose, "Backing up volume by adding it through GUI");
                    MainForm.Instance.BackupVolume(vdesc);
                }
            }
            catch (System.Exception ex)
            {
                Log.WriteException("Add new volume failed", ex);
            }

            MainForm.Instance.ControlSwitcher.SwitchUserControl(FormControlType.Welcome, FormControlSwitchType.Finish);
        }
示例#2
0
        /// <summary>
        /// Get the Stream related to a file
        /// </summary>
        /// <param name="datItem">Information for the current file to rebuild from</param>
        /// <param name="file">Name of the file to process</param>
        /// <param name="isZip">Non-null if the input file is an archive</param>
        /// <param name="stream">Output stream representing the opened file</param>
        /// <returns>True if the stream opening succeeded, false otherwise</returns>
        private static bool GetFileStream(DatItem datItem, string file, bool?isZip, out Stream stream)
        {
            // Get a generic stream for the file
            stream = null;

            // If we have a zipfile, extract the stream to memory
            if (isZip != null)
            {
                BaseArchive archive = BaseArchive.Create(file);
                if (archive != null)
                {
                    (stream, _) = archive.CopyToStream(datItem.GetName() ?? datItem.ItemType.ToString());
                }
            }
            // Otherwise, just open the filestream
            else
            {
                stream = File.OpenRead(file);
            }

            // If the stream is null, then continue
            if (stream == null)
            {
                return(false);
            }

            // Seek to the beginning of the stream
            if (stream.CanSeek)
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            return(true);
        }
示例#3
0
        private void btnMoveRar_Click(object sender, EventArgs e)
        {
            BaseArchive   b       = new BaseArchive();
            DirectoryInfo dir     = new DirectoryInfo(BaseArchive.ORIGINAL_FILES_PATH);
            DirectoryInfo SiteDir = new DirectoryInfo(System.Configuration.ConfigurationManager.AppSettings["SITE_DIR"]);

            FileInfo[] files = dir.GetFiles();
            if (files.Length > 0)
            {
                string fileName = Path.Combine(SiteDir.FullName, DateTime.Now.Ticks.ToString() + ".rar");
                files[0].MoveTo(fileName);
                bool res = Toolkit.Web.Mailer.Send("*****@*****.**", "log Was created", fileName, "*****@*****.**", true);
                MessageBox.Show(string.Format("FILE {0} has transfer and was sent {1}", fileName, res), "", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show("NO FILE", "", MessageBoxButtons.OK);
            }
        }
        public VolumeDescriptor(VolumeEventController eventController, string volName, string volFilename, VolumeSource source, BaseArchive archive)
        {
            mEventController = eventController;
            mName            = volName;
            mVolumeFilename  = volFilename;

            mVolume = new Volume(mEventController, this, source, archive);
            ConnectToVolumeEvents(mVolume);
            mIsAvailable = true;
            SaveVolumeData();
        }
示例#5
0
        /// <summary>
        /// Process blank folders in an archive
        /// </summary>
        /// <param name="datFile">Current DatFile object to add to</param>
        /// <param name="item">File containing the blanks</param>
        /// <param name="basePath">Path the represents the parent directory</param>
        /// <param name="archive">BaseArchive to get blanks from</param>
        private static void ProcessArchiveBlanks(DatFile datFile, string item, string basePath, BaseArchive archive)
        {
            List <string> empties = new List <string>();

            // Get the parent path for all items
            string parent = (Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item);

            // Now get all blank folders from the archive
            if (archive != null)
            {
                empties = archive.GetEmptyFolders();
            }

            // Add add all of the found empties to the DAT
            Parallel.ForEach(empties, Globals.ParallelOptions, empty =>
            {
                Rom emptyRom = new Rom(Path.Combine(empty, "_"), item);
                ProcessFileHelper(datFile, item, emptyRom, basePath, parent);
            });
        }
示例#6
0
        /// <summary>
        /// Check a given file for hashes, based on current settings
        /// </summary>
        /// <param name="datFile">Current DatFile object to add to</param>
        /// <param name="item">Filename of the item to be checked</param>
        /// <param name="basePath">Base folder to be used in creating the DAT</param>
        /// <param name="asFiles">TreatAsFiles representing CHD and Archive scanning</param>
        /// <param name="skipFileType">Type of files that should be skipped</param>
        /// <param name="addBlanks">True if blank items should be created for empty folders, false otherwise</param>
        /// <param name="hashes">Hashes to include in the information</param>
        private static void CheckFileForHashes(
            DatFile datFile,
            string item,
            string basePath,
            TreatAsFile asFiles,
            SkipFileType skipFileType,
            bool addBlanks,
            Hash hashes)
        {
            // If we're in depot mode, process it separately
            if (CheckDepotFile(datFile, item))
            {
                return;
            }

            // Initialize possible archive variables
            BaseArchive archive = BaseArchive.Create(item);

            // Process archives according to flags
            if (archive != null)
            {
                // Set the archive flags
                archive.AvailableHashes = hashes;

                // Skip if we're treating archives as files and skipping files
                if (asFiles.HasFlag(TreatAsFile.Archive) && skipFileType == SkipFileType.File)
                {
                    return;
                }

                // Skip if we're skipping archives
                else if (skipFileType == SkipFileType.Archive)
                {
                    return;
                }

                // Process as archive if we're not treating archives as files
                else if (!asFiles.HasFlag(TreatAsFile.Archive))
                {
                    var extracted = archive.GetChildren();

                    // If we have internal items to process, do so
                    if (extracted != null)
                    {
                        ProcessArchive(datFile, item, basePath, extracted);
                    }

                    // Now find all folders that are empty, if we are supposed to
                    if (addBlanks)
                    {
                        ProcessArchiveBlanks(datFile, item, basePath, archive);
                    }
                }

                // Process as file if we're treating archives as files
                else
                {
                    ProcessFile(datFile, item, basePath, hashes, asFiles);
                }
            }

            // Process non-archives according to flags
            else
            {
                // Skip if we're skipping files
                if (skipFileType == SkipFileType.File)
                {
                    return;
                }

                // Process as file
                else
                {
                    ProcessFile(datFile, item, basePath, hashes, asFiles);
                }
            }
        }
        public VolumeDescriptor AddNewDescriptor(string volName, string volFilename, VolumeSource source, BaseArchive archive)
        {
            VolumeDescriptor vd = new VolumeDescriptor(mEventController, volName, volFilename, source, archive);

            lock ( mDescriptorList )
            {
                mDescriptorList.Add(vd);
            }
            Config.Active.Save();
            return(vd);
        }
示例#8
0
 public RegionArchive(State state, string path)
     : base(state)
 {
     archive = new BaseArchive(state, path);
     regions = new Region[archive.RecordMap.Count / 4];
 }
示例#9
0
 public Volume(VolumeEventController eventController, VolumeDescriptor volumeDesc, VolumeSource source, BaseArchive archive)
 {
     mEventController     = eventController;
     mVolumeDesc          = volumeDesc;
     mBackupRestoreObject = new BackupRestoreVolume(mVolumeDesc.VolumeName, source, archive);
     Init();
 }
示例#10
0
        /// <summary>
        /// Attempt to add a file to the output if it matches
        /// </summary>
        /// <param name="datFile">Current DatFile object to rebuild from</param>
        /// <param name="file">Name of the file to process</param>
        /// <param name="outDir">Output directory to use to build to</param>
        /// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
        /// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
        /// <param name="inverse">True if the DAT should be used as a filter instead of a template, false otherwise</param>
        /// <param name="outputFormat">Output format that files should be written to</param>
        /// <param name="asFiles">TreatAsFiles representing special format scanning</param>
        /// <returns>True if the file was used to rebuild, false otherwise</returns>
        private static bool RebuildGenericHelper(
            DatFile datFile,
            string file,
            string outDir,
            bool quickScan,
            bool date,
            bool inverse,
            OutputFormat outputFormat,
            TreatAsFile asFiles)
        {
            // If we somehow have a null filename, return
            if (file == null)
            {
                return(false);
            }

            // Set the deletion variables
            bool usedExternally = false, usedInternally = false;

            // Create an empty list of BaseFile for archive entries
            List <BaseFile> entries = null;

            // Get the TGZ and TXZ status for later
            GZipArchive tgz             = new GZipArchive(file);
            XZArchive   txz             = new XZArchive(file);
            bool        isSingleTorrent = tgz.IsTorrent() || txz.IsTorrent();

            // Get the base archive first
            BaseArchive archive = BaseArchive.Create(file);

            // Now get all extracted items from the archive
            if (archive != null)
            {
                archive.AvailableHashes = quickScan ? Hash.CRC : Hash.Standard;
                entries = archive.GetChildren();
            }

            // If the entries list is null, we encountered an error or have a file and should scan externally
            if (entries == null && File.Exists(file))
            {
                BaseFile internalFileInfo = BaseFile.GetInfo(file, asFiles: asFiles);

                // Create the correct DatItem
                DatItem internalDatItem;
                if (internalFileInfo.Type == FileType.AaruFormat && !asFiles.HasFlag(TreatAsFile.AaruFormat))
                {
                    internalDatItem = new Media(internalFileInfo);
                }
                else if (internalFileInfo.Type == FileType.CHD && !asFiles.HasFlag(TreatAsFile.CHD))
                {
                    internalDatItem = new Disk(internalFileInfo);
                }
                else
                {
                    internalDatItem = new Rom(internalFileInfo);
                }

                usedExternally = RebuildIndividualFile(datFile, internalDatItem, file, outDir, date, inverse, outputFormat);
            }
            // Otherwise, loop through the entries and try to match
            else
            {
                foreach (BaseFile entry in entries)
                {
                    DatItem internalDatItem = DatItem.Create(entry);
                    usedInternally |= RebuildIndividualFile(datFile, internalDatItem, file, outDir, date, inverse, outputFormat, !isSingleTorrent /* isZip */);
                }
            }

            return(usedExternally || usedInternally);
        }