AcManager.Tools.GameProperties.WeatherSpecificDirectoryReplacement.Apply C# (CSharp) Method

Apply() public method

public Apply ( WeatherObject weather ) : bool
weather AcManager.Tools.Objects.WeatherObject
return bool
        public bool Apply(WeatherObject weather) {
            if (AcRootDirectory.Instance.Value == null) return false;

            var source = Path.Combine(weather.Location, RelativeSource);
            if (!Directory.Exists(source)) return false;

            var destination = Path.Combine(AcRootDirectory.Instance.RequireValue, RelativeDestination);
            var backup = Path.Combine(AcRootDirectory.Instance.RequireValue, RelativeBackup);

            if (Directory.Exists(destination)) {
                if (Directory.Exists(backup)) {
                    Directory.Move(backup, FileUtils.EnsureUnique(backup));
                }

                Logging.Debug($"{destination} → {backup}");
                Directory.Move(destination, backup);
            }


            try {
                Logging.Debug($"{source} → {destination}");
                FileUtils.CopyRecursiveHardlink(source, destination);
            } catch (Exception e) {
                // this exception should be catched here so original clouds folder still
                // will be restored even when copying a new one has been failed
                NonfatalError.Notify("Can’t replace weather-specific directory", e);
            }

            return true;
        }