BGC Tools
Static Public Member Functions | Properties | Static Private Member Functions | Static Private Attributes
BGC.IO.DataManagement Class Reference
Collaboration diagram for BGC.IO.DataManagement:
Collaboration graph
[legend]

Static Public Member Functions

static IEnumerable< string > GetDataFiles (string dataDirectory)
 Get a list of all data files in sub directory of os data directory More...
 
static string PathForDataFile (string dataDirectory, string fileName)
 Returns the full path for specified datafile in a data directory More...
 
static string PathForDataDirectory (string dataDirectory)
 Returns the full path to the dataDirectory directory. More...
 
static bool DataDirectoryExists (string dataDirectory)
 
static string PathForDataSubDirectory (params string[] dataDirectories)
 Returns the full path to the dataDirectories directory. More...
 
static string NextAvailableFilePath (string filepath)
 Returns an available filepath. Appends " (#)" to the filename, incrementing # until it is available, starting with any modifier present in the filepath. More...
 

Properties

static string RootDirectory [get]
 Root directory for all users data More...
 

Static Private Member Functions

static string GetCleanFileName (string fileName, out int modifierValue)
 Identifies any filename matching the pattern "NameStuffHere (3)" and strips off and spits out the modifier More...
 

Static Private Attributes

static string rootDirectory = null
 

Detailed Description

Definition at line 7 of file DataManagement.cs.

Member Function Documentation

◆ DataDirectoryExists()

static bool BGC.IO.DataManagement.DataDirectoryExists ( string  dataDirectory)
static

Referenced by BGC.Audio.Spatialization.ImpulseExtraction.PrepareRun().

Here is the caller graph for this function:

◆ GetCleanFileName()

static string BGC.IO.DataManagement.GetCleanFileName ( string  fileName,
out int  modifierValue 
)
inlinestaticprivate

Identifies any filename matching the pattern "NameStuffHere (3)" and strips off and spits out the modifier

Definition at line 82 of file DataManagement.cs.

83  {
84  //If FileName doesn't end with " (##)", it's not a modifier
85  if (fileName.EndsWith(")") && fileName.Contains(" ("))
86  {
87  //FileName ends with (##)
88  //It may have a modifier
89 
90  int indexOfOpen = fileName.LastIndexOf(" (");
91  int indexOfClose = fileName.LastIndexOf(")");
92 
93  int indexInside = indexOfOpen + 2;
94  int length = indexOfClose - indexInside;
95 
96  //Make sure there are contents
97  //This would reject "TestFile ()"
98  if (length > 0)
99  {
100  string valueString = fileName.Substring(indexInside, length);
101 
102  //Make sure value string can be parsed entirely, otherwise its not a modifier
103  //This would reject "TestFile (words)"
104  if (int.TryParse(valueString, out modifierValue))
105  {
106  //Reject negative numbers because that's now how we create modifiers
107  //This would reject "Test File (-1)"
108  if (modifierValue > 0)
109  {
110  modifierValue++;
111  return fileName.Substring(0, indexOfOpen);
112  }
113  }
114  }
115  }
116 
117  modifierValue = 2;
118  return fileName;
119  }

◆ GetDataFiles()

static IEnumerable<string> BGC.IO.DataManagement.GetDataFiles ( string  dataDirectory)
static

Get a list of all data files in sub directory of os data directory

Referenced by BGC.Users.PlayerData.DeserializeUsers().

Here is the caller graph for this function:

◆ NextAvailableFilePath()

static string BGC.IO.DataManagement.NextAvailableFilePath ( string  filepath)
inlinestatic

Returns an available filepath. Appends " (#)" to the filename, incrementing # until it is available, starting with any modifier present in the filepath.

Returns
An available filepath

Definition at line 127 of file DataManagement.cs.

Referenced by BGC.Audio.Midi.MidiEncoding.SaveFile().

128  {
129  if (!File.Exists(filepath))
130  {
131  return filepath;
132  }
133 
134  string directory = Path.GetDirectoryName(filepath);
135  string fileExtension = Path.GetExtension(filepath);
136  string fileName = GetCleanFileName(
137  fileName: Path.GetFileNameWithoutExtension(filepath),
138  modifierValue: out int initialModifierValue);
139 
140  for (int i = initialModifierValue; ; i++)
141  {
142  if (!File.Exists(filepath))
143  {
144  return filepath;
145  }
146 
147  filepath = Path.Combine(directory, $"{fileName} ({i}){fileExtension}");
148  }
149  }
static string GetCleanFileName(string fileName, out int modifierValue)
Identifies any filename matching the pattern "NameStuffHere (3)" and strips off and spits out the mod...
Here is the caller graph for this function:

◆ PathForDataDirectory()

static string BGC.IO.DataManagement.PathForDataDirectory ( string  dataDirectory)
inlinestatic

Returns the full path to the dataDirectory directory.

Definition at line 41 of file DataManagement.cs.

Referenced by BGC.Study.ProtocolManager.LoadProtocolSet(), BGC.Audio.Spatialization.ImpulseExtraction.PrepareRun(), BGC.Study.ProtocolManager.SerializeAll(), and BGC.Study.ProtocolManager.UpdateDefaults().

42  {
43  string path = Path.Combine(RootDirectory, dataDirectory);
44 
45  if (Directory.Exists(path) == false)
46  {
47  Directory.CreateDirectory(path);
48  }
49 
50  return path;
51  }
static string RootDirectory
Root directory for all users data
Here is the caller graph for this function:

◆ PathForDataFile()

static string BGC.IO.DataManagement.PathForDataFile ( string  dataDirectory,
string  fileName 
)
static

Returns the full path for specified datafile in a data directory

Referenced by BGC.Tests.SynthesisTests.FMTestBell(), BGC.Tests.SynthesisTests.FMTestBrass(), BGC.Tests.SynthesisTests.FMTestDrum(), BGC.Tests.SynthesisTests.FMTestOvertones(), BGC.Tests.SynthesisTests.FMTestPiano(), BGC.Tests.SynthesisTests.FMTestTrianglePiano(), BGC.Audio.Spatial.GetFilterFilename(), BGC.Audio.Calibration.Initialize(), BGC.Audio.Spatialization.ImpulseExtraction.PrepareRun(), BGC.Audio.Calibration.Serialize(), BGC.Tests.SynthesisTests.SmallAnalyticFMTest(), BGC.Tests.SynthesisTests.SmallSineFMTest(), BGC.Tests.SynthesisTests.SynthTestSnare(), BGC.Tests.SynthesisTests.TestAllPassFilterSpeech(), BGC.Tests.SynthesisTests.TestBiQuadFilters(), BGC.Tests.TestOverlapAdd.TestCarlileShuffler(), BGC.Tests.SynthesisTests.TestCarrierModifiedFakeVoices(), BGC.Tests.MidiEncodingTests.TestContinuousFilter(), BGC.Tests.WAVEncodingTests.TestDualChannelWave(), BGC.Tests.SynthesisTests.TestFakeVoice(), BGC.Tests.SynthesisTests.TestFDComposer(), BGC.Tests.SynthesisTests.TestFDComposerPure(), BGC.Tests.MidiEncodingTests.TestFlute(), BGC.Tests.SynthesisTests.TestFMFilterVoice(), BGC.Tests.SynthesisTests.TestFrequencyShifter(), BGC.Tests.SynthesisTests.TestFunFakeVoice(), BGC.Tests.MidiEncodingTests.TestGuitar(), BGC.Tests.MidiEncodingTests.TestHiHat(), BGC.Tests.MidiEncodingTests.TestLoadSaveMidiBare(), BGC.Tests.MidiEncodingTests.TestLoadSaveMidiFull(), BGC.Tests.TestOverlapAdd.TestNewConvolution(), BGC.Tests.TestOverlapAdd.TestNewSpatialization(), BGC.Tests.MidiEncodingTests.TestOrgan(), BGC.Tests.SynthesisTests.TestPhaseReEncoder(), BGC.Tests.TestOverlapAdd.TestPhaseVocoding(), BGC.Tests.MidiEncodingTests.TestPulses(), BGC.Tests.MidiEncodingTests.TestRenderMidi(), BGC.Tests.MidiEncodingTests.TestRenderToccataMidi(), BGC.Tests.SynthesisTests.TestSawtoothWave(), BGC.Tests.SynthesisTests.TestSineWave(), BGC.Tests.WAVEncodingTests.TestSingleChannelWave(), BGC.Tests.MidiEncodingTests.TestSnare(), BGC.Tests.SynthesisTests.TestSquareWave(), BGC.Tests.SynthesisTests.TestSTM(), BGC.Tests.SynthesisTests.TestTriangleWave(), BGC.Tests.ZipTests.TestZip(), BGC.Tests.SynthesisTests.TryAllPassFilter(), BGC.Tests.SynthesisTests.TryFMFilter(), and BGC.Tests.WAVEncodingTests.UpScalingTest().

Here is the caller graph for this function:

◆ PathForDataSubDirectory()

static string BGC.IO.DataManagement.PathForDataSubDirectory ( params string []  dataDirectories)
inlinestatic

Returns the full path to the dataDirectories directory.

Definition at line 57 of file DataManagement.cs.

Referenced by BGC.Tests.ZipTests.TestZip().

58  {
59  string[] paths = new string[dataDirectories.Length + 1];
60  paths[0] = RootDirectory;
61  System.Array.Copy(
62  sourceArray: dataDirectories,
63  sourceIndex: 0,
64  destinationArray: paths,
65  destinationIndex: 1,
66  length: dataDirectories.Length);
67 
68  string path = Path.Combine(paths);
69 
70  if (Directory.Exists(path) == false)
71  {
72  Directory.CreateDirectory(path);
73  }
74 
75  return path;
76  }
static string RootDirectory
Root directory for all users data
Here is the caller graph for this function:

Field Documentation

◆ rootDirectory

string BGC.IO.DataManagement.rootDirectory = null
staticprivate

Definition at line 9 of file DataManagement.cs.

Property Documentation

◆ RootDirectory

string BGC.IO.DataManagement.RootDirectory
staticget

Root directory for all users data

Definition at line 13 of file DataManagement.cs.


The documentation for this class was generated from the following file: