Beispiel #1
0
 public ParitySet(Config config, IEnvironment environment)
 {
     drives = new List<DataDrive>();
       Config = config;
       parity = new Parity(Config);
       Empty = true;
       env = environment;
 }
        public DataDriveViewModel(DataDrive dataDrive, Config config)
        {
            this.config = config;
              DataDrive = dataDrive;
              DataDrive.PropertyChanged += HandlePropertyChanged;
              DataDrive.ChangesDetected += HandleChangesDetected;
              UpdateStatus();
              UpdateFileCount();
              UpdateAdditionalInfo();

              autoScanTimer = new System.Timers.Timer(1000);
              autoScanTimer.AutoReset = true;
              autoScanTimer.Elapsed += HandleAutoScanTimer;
        }
        public MainWindowViewModel(Window owner)
        {
            this.owner = owner;
              // Set up application data and log folders
              string appDataPath = Utils.AppDataFolder;
              if (!Directory.Exists(appDataPath))
            Directory.CreateDirectory(appDataPath);
              string logPath = Path.Combine(appDataPath, "logs");
              if (!Directory.Exists(logPath))
            Directory.CreateDirectory(logPath);
              LogFile.Open(Path.Combine(logPath, "disParity.log"), false);
              LogFile.Log("Application launched (version {0})", disParity.Version.VersionString);

              updateTimer = new System.Timers.Timer(1000);
              updateTimer.AutoReset = true;
              updateTimer.Elapsed += HandleUpdateTimer;

              updateParityStatusTimer = new System.Timers.Timer(1000);
              updateParityStatusTimer.AutoReset = true;
              updateParityStatusTimer.Elapsed += UpdateParityStatus;

              pingTimer = new System.Timers.Timer(TimeSpan.FromHours(24).TotalMilliseconds);
              pingTimer.AutoReset = true;
              pingTimer.Elapsed += HandlePingTimer;

              operationManager = new OperationManager(this);
              operationManager.OperationFinished += HandleOperationFinished;

              // Try to load the config.xml now, we need it to set the main window position.
              // If it fails, use default values for everything and display a dialog in Loaded()
              try {
            config = new Config(Path.Combine(Utils.AppDataFolder, "Config.xml"));
            if (config.Exists) {
              config.Load();
              config.Validate();
            }
              }
              catch (Exception e) {
            configLoadException = e;
            config.MakeBackup();
            config.Reset();
              }

              Left = config.MainWindowX;
              Top = config.MainWindowY;
              Height = config.MainWindowHeight;
              Width = config.MainWindowWidth;
        }
Beispiel #4
0
 public ParityChange(Parity parity, Config config, UInt32 startBlock, UInt32 lengthInBlocks)
 {
     this.parity = parity;
       this.startBlock = startBlock;
       tempDir = config.TempDir;
       writingToMMF = true;
       UInt32 maxMMFBlocks = Parity.LengthInBlocks((long)config.MaxTempRAM * 1024 * 1024);
       UInt32 mmfBlocks = (lengthInBlocks < maxMMFBlocks) ? lengthInBlocks : maxMMFBlocks;
       try {
     mmf = MemoryMappedFile.CreateNew("disparity.tmp", (long)mmfBlocks * Parity.BLOCK_SIZE);
     mmfStream = mmf.CreateViewStream();
       }
       catch (Exception e) {
     LogFile.Log("Could not create memory mapped file: " + e.Message);
     // We'll use a temp file only
     mmf = null;
     mmfStream = null;
     writingToMMF = false;
       }
       tempFileStream = null;
       parityBlock = new ParityBlock(parity);
       block = startBlock;
 }
Beispiel #5
0
        public DataDrive(string root, string metaFile, Config config, IEnvironment environment)
        {
            this.root = root;
              this.metaFile = metaFile;
              this.config = config;
              this.env = environment;

              if (!root.StartsWith(@"\\")) {
            string drive = Path.GetPathRoot(root);
            if (!String.IsNullOrEmpty(drive))
              try {
            DriveInfo driveInfo = new DriveInfo(drive);
            DriveType = driveInfo.DriveType;
            VolumeLabel = driveInfo.VolumeLabel;
            TotalSpace = driveInfo.TotalSize;
              }
              catch {
            DriveType = DriveType.Unknown;
              }
              }
              else
            DriveType = DriveType.Network;

              hash = MD5.Create();
              files = new Dictionary<string, FileRecord>();
              Reset();

              fileCloseTimer = new Timer(1000); // keep cached read files open for at most one second
              fileCloseTimer.AutoReset = false;
              fileCloseTimer.Elapsed += HandleFileCloseTimer;

              if (config.MonitorDrives)
            EnableWatcher();

              LastScanStart = DateTime.MinValue;
              LastChanges = DateTime.Now - TimeSpan.FromSeconds(55); // REMOVEME
        }
Beispiel #6
0
        private UInt32 maxBlock; // the highest allocated block so far (i.e. exists on disk, not necessarily in use by the app

        #endregion Fields

        #region Constructors

        public Parity(Config config)
        {
            this.config = config;
              ComputeMaxBlock();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            string recoverDir = "";
              Command cmd = Command.None;
              bool verbose = false;

              if (args.Length > 0) {
            if (args[0].ToLower() == "update")
              cmd = Command.Update;
            else if (args[0].ToLower() == "verify") {
              cmd = Command.Verify;
            }
            else if ((args.Length == 3) && args[0].ToLower() == "recover") {
              cmd = Command.Recover;
              if (!ReadDriveNum(args))
            return;
              recoverDir = args[2];
            }
            else if ((args.Length == 2) && args[0].ToLower() == "test") {
              cmd = Command.Test;
              if (!ReadDriveNum(args))
            return;
            }
            else if (args[0].ToLower() == "list") {
              cmd = Command.List;
              if (args.Length == 2) {
            if (!ReadDriveNum(args))
              return;
              }
            }
            else if (args[0].ToLower() == "stats")
              cmd = Command.Stats;
            else if (args[0].ToLower() == "hashcheck") {
              cmd = Command.HashCheck;
              if (args.Length == 2) {
            if (!ReadDriveNum(args))
              return;
              }
            }
            else if (args[0].ToLower() == "monitor") {
              verbose = true;
              cmd = Command.Monitor;
            }
            else if (args[0].ToLower() == "undelete") {
              cmd = Command.Undelete;
              if (!ReadDriveNum(args))
            return;
            }

              }

              if (args.Length > 1 && (cmd == Command.Update || cmd == Command.Verify)) {
            if (args[1].ToLower() == "-v")
              verbose = true;
            else {
              PrintUsage();
              return;
            }
              }

              if (cmd == Command.None) {
            PrintUsage();
            return;
              }

              if (SingleInstance.AlreadyRunning()) {
            Console.WriteLine("Another instance of disParity is currently running.");
            return;
              }

              disParity.Version.DoUpgradeCheck(HandleNewVersionAvailable);

              string appDataPath = Utils.AppDataFolder;
              if (!Directory.Exists(appDataPath))
            Directory.CreateDirectory(appDataPath);
              string logPath = Path.Combine(appDataPath, "logs");
              if (!Directory.Exists(logPath))
            Directory.CreateDirectory(logPath);

              string logFileName = Path.Combine(logPath, "disParity " + DateTime.Now.ToString("yy-MM-dd HH.mm.ss"));
              LogFile.Open(logFileName, verbose);
              LogFile.Write("Beginning \"{0}\" command at {1} on {2}\r\n", args[0].ToLower(),
            DateTime.Now.ToShortTimeString(), DateTime.Today.ToLongDateString());

              string ConfigPath = Path.Combine(appDataPath, "Config.xml");
              try {
            config = new Config(ConfigPath);
            config.Load();
              }
              catch (Exception e) {
            LogFile.Write("Could not load Config file: " + e.Message);
            return;
              }

              try {
            ParitySet set = new ParitySet(config, null);  // <--- FIX ME, need to pass actual environment here
            set.ReloadDrives();
            switch (cmd) {
              case Command.Update:
            set.Update(true);
            break;

              case Command.Recover:
            int successes;
            int failures;
            set.Recover(set.Drives[driveNum], recoverDir, out successes, out failures);
            break;

              case Command.HashCheck:
            if (driveNum != -1)
              set.HashCheck(set.Drives[driveNum]);
            //else
            //  set.HashCheck();
            break;
            }
              }
              catch (Exception e) {
            LogFile.Log("Fatal error encountered during {0}: {1}",
              args[0].ToLower(), e.Message);
            LogFile.Log("Stack trace: {0}", e.StackTrace);
              }
              finally {
            if (!String.IsNullOrEmpty(shutdownMsg))
              LogFile.Write(shutdownMsg);
            LogFile.Close();
              }
        }
 public OptionsDialogViewModel(ParitySet paritySet)
 {
     this.paritySet = paritySet;
       config = paritySet.Config;
       SetProperties();
 }