public void IncreaseSizeFile(int _oldSize) { //New number cluster var nCluster = (int)Math.Ceiling((decimal)Size / Settings.Settings.ClusterSize); var remainingSize = Size - _oldSize; var color = FragmentFiles.First().Color; //Change size last cluster var lastFragmentFile = FragmentFiles.Last(); remainingSize -= (Settings.Settings.ClusterSize - lastFragmentFile.Size); lastFragmentFile.Size = Settings.Settings.ClusterSize; //Calculate size of fragmentfile var calcSize = remainingSize; if (calcSize > Settings.Settings.ClusterSize) { calcSize = Settings.Settings.ClusterSize; } for (var i = NumberClusterUse + 1; i <= nCluster; i++) { FragmentFiles.Add(new FragmentClusterFile { Name = Name + $"_{i}", Size = calcSize, Color = color }); remainingSize -= Settings.Settings.ClusterSize; if (remainingSize < Settings.Settings.ClusterSize) { calcSize = remainingSize; } } //Update NumberClusterUse NumberClusterUse = nCluster; }
public void DecreseSizeFile(int _oldSize) { //New number cluster var nCluster = (int)Math.Ceiling((decimal)Size / Settings.Settings.ClusterSize); //Remove fragmentfile for (var i = nCluster; i < NumberClusterUse; i++) { if (FragmentFiles.Count > 0) { FragmentFiles.RemoveAt(FragmentFiles.Count - 1); } } if (FragmentFiles.Count > 0) { //Update last fragment size and nextcluster var lastFragmentFile = FragmentFiles.Last(); lastFragmentFile.Size = Size - ((nCluster - 1) * Settings.Settings.ClusterSize); lastFragmentFile.NextCluster = null; } //Update NumberClusterUse NumberClusterUse = nCluster; }