| 200 | // CWorldSoundsDialog message handlers |
| 201 | |
| 202 | void CWorldSoundsDialog::OnAddSound() { |
| 203 | char filename[256], dir[256], fname[128], ext[32]; |
| 204 | char cur_name[100]; |
| 205 | int raw_handle; |
| 206 | int sound_handle; |
| 207 | int c = 1, finding_name = 1; |
| 208 | |
| 209 | if (!Network_up) { |
| 210 | OutrageMessageBox("Sorry babe, the network is down. This action is a no-no.\n"); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | // Get the filename of the representing image |
| 215 | |
| 216 | CString filter = "Descent III files (*.wav)|*.wav||"; |
| 217 | |
| 218 | if (!OpenFileDialog(this, (LPCSTR)filter, filename, Current_sounds_dir, sizeof(Current_sounds_dir))) |
| 219 | return; |
| 220 | |
| 221 | ddio_SplitPath(filename, dir, fname, ext); |
| 222 | |
| 223 | // Okay, we selected a file. Lets do what needs to be done here. |
| 224 | raw_handle = LoadSoundFile(filename, 1.0f, true); |
| 225 | |
| 226 | if (raw_handle < 0) { |
| 227 | OutrageMessageBox("Invalid sound file."); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | // Alloc a sound and give a name not already taken by some other sound |
| 232 | |
| 233 | sound_handle = AllocSound(); |
| 234 | |
| 235 | while (finding_name) { |
| 236 | if (c == 1) |
| 237 | sprintf(cur_name, "%s", fname); |
| 238 | else |
| 239 | sprintf(cur_name, "%s%d", fname, c); |
| 240 | if (FindSoundName(cur_name) != -1) |
| 241 | c++; |
| 242 | else |
| 243 | finding_name = 0; |
| 244 | } |
| 245 | |
| 246 | strcpy(Sounds[sound_handle].name, cur_name); |
| 247 | |
| 248 | Sounds[sound_handle].sample_index = raw_handle; |
| 249 | |
| 250 | // Finally, save a local copy of the .wav and alloc a tracklock |
| 251 | mprintf(0, "Making a copy of this sound locally...\n"); |
| 252 | |
| 253 | std::filesystem::path destname = LocalSoundsDir / SoundFiles[Sounds[sound_handle].sample_index].name; |
| 254 | cf_CopyFile(destname, filename); |
| 255 | |
| 256 | mng_AllocTrackLock(cur_name, PAGETYPE_SOUND); |
| 257 | |
| 258 | D3EditState.current_sound = sound_handle; |
| 259 |
nothing calls this directly
no test coverage detected