Browse Source

Append .vcv to files that are saved with no extension

tags/v0.4.0
Andrew Belt 7 years ago
parent
commit
bdcbe508db
3 changed files with 34 additions and 9 deletions
  1. +10
    -1
      include/util.hpp
  2. +15
    -8
      src/app/RackWidget.cpp
  3. +9
    -0
      src/util.cpp

+ 10
- 1
include/util.hpp View File

@@ -62,7 +62,7 @@ float randomf();
float randomNormal();

////////////////////
// Helper functions
// String functions
////////////////////

/** Converts a printf format string and optional arguments into a std::string */
@@ -73,6 +73,11 @@ std::string ellipsize(std::string s, size_t len);

std::string extractDirectory(std::string path);
std::string extractFilename(std::string path);
std::string extractExtension(std::string path);

////////////////////
// Operating system functions
////////////////////

/** Opens a URL, also happens to work with PDFs and folders.
Shell injection is possible, so make sure the URL is trusted or hard coded.
@@ -80,6 +85,10 @@ May block, so open in a new thread.
*/
void openBrowser(std::string url);

////////////////////
// Thread functions
////////////////////

/** Threads which obtain a VIPLock will cause wait() to block for other less important threads.
This does not provide the VIPs with an exclusive lock. That should be left up to another mutex shared between the less important thread.
*/


+ 15
- 8
src/app/RackWidget.cpp View File

@@ -60,17 +60,24 @@ void RackWidget::saveDialog() {
void RackWidget::saveAsDialog() {
std::string dir = lastPath.empty() ? assetLocal("") : extractDirectory(lastPath);
char *path = osdialog_file(OSDIALOG_SAVE, dir.c_str(), "Untitled.vcv", NULL);

if (path) {
savePatch(path);
lastPath = path;
std::string pathStr = path;
free(path);
std::string extension = extractExtension(pathStr);
if (extension.empty()) {
pathStr += ".vcv";
}

savePatch(pathStr);
lastPath = pathStr;
}
}


void RackWidget::savePatch(std::string filename) {
printf("Saving patch %s\n", filename.c_str());
FILE *file = fopen(filename.c_str(), "w");
void RackWidget::savePatch(std::string path) {
printf("Saving patch %s\n", path.c_str());
FILE *file = fopen(path.c_str(), "w");
if (!file)
return;

@@ -83,9 +90,9 @@ void RackWidget::savePatch(std::string filename) {
fclose(file);
}

void RackWidget::loadPatch(std::string filename) {
printf("Loading patch %s\n", filename.c_str());
FILE *file = fopen(filename.c_str(), "r");
void RackWidget::loadPatch(std::string path) {
printf("Loading patch %s\n", path.c_str());
FILE *file = fopen(path.c_str(), "r");
if (!file) {
// Exit silently
return;


+ 9
- 0
src/util.cpp View File

@@ -36,10 +36,12 @@ float randomNormal(){
std::string stringf(const char *format, ...) {
va_list args;
va_start(args, format);
// Compute size of required buffer
int size = vsnprintf(NULL, 0, format, args);
va_end(args);
if (size < 0)
return "";
// Create buffer
std::string s;
s.resize(size);
va_start(args, format);
@@ -69,6 +71,13 @@ std::string extractFilename(std::string path) {
return filename;
}

std::string extractExtension(std::string path) {
const char *ext = strrchr(path.c_str(), '.');
if (!ext)
return "";
return ext + 1;
}

void openBrowser(std::string url) {
#if ARCH_LIN
std::string command = "xdg-open " + url;


Loading…
Cancel
Save