Skip to content

Commit

Permalink
Fixes the recovery for cloud projects
Browse files Browse the repository at this point in the history
  • Loading branch information
crsib committed Dec 15, 2023
1 parent dc66ed5 commit ca7df92
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
14 changes: 10 additions & 4 deletions libraries/lib-cloud-audiocom/CloudSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
#include "CloudSettings.h"

#include "FileNames.h"
#include "wxFileNameWrapper.h"

namespace cloud::audiocom
{
StringSetting CloudProjectsSavePath { "/cloud/audiocom/CloudProjectsSavePath",
[] {
return FileNames::DataDir() + "/cloud";
} };
StringSetting CloudProjectsSavePath {
"/cloud/audiocom/CloudProjectsSavePath",
[]
{
wxFileNameWrapper path { FileNames::DataDir(), "" };
path.AppendDir("CloudProjects");
return path.GetPath();
}
};
} // namespace cloud::audiocom
15 changes: 3 additions & 12 deletions libraries/lib-cloud-audiocom/CloudSyncService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "sync/CloudProjectSnapshot.h"
#include "sync/ProjectCloudExtension.h"
#include "sync/CloudSyncUI.h"
#include "sync/CloudSyncUtils.h"

#include "CodeConversions.h"

Expand All @@ -31,6 +32,7 @@
#include "FileNames.h"

#include <wx/log.h>
#include "wxFileNameWrapper.h"


namespace cloud::audiocom
Expand Down Expand Up @@ -74,18 +76,7 @@ bool CloudSyncService::OnSave(AudacityProject& project, bool fromTempProject)

project.SetProjectName(audacity::ToWXString(result.Title));

wxString filePath;
bool available = false;

auto potentialFileId =
std::chrono::system_clock::now().time_since_epoch().count();

while (!available)
{
filePath = wxString::Format("%s/%lld.aup3", dir, potentialFileId);
available = !wxFileName::FileExists(filePath);
++potentialFileId;
}
const wxString filePath = sync::MakeSafeProjectPath(dir, audacity::ToWXString(result.Title));

return ProjectFileIO::Get(project).SaveProject(filePath, nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/lib-cloud-audiocom/sync/CloudProjectSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void CloudProjectSnapshot::OnSnapshotCreated(
if (completed)
{
mCompleted.store(true, std::memory_order_release);
mProjectCloudExtension.OnSyncCompleted(succeeded);
mProjectCloudExtension.OnSyncCompleted(false);
}
});
}
Expand Down
36 changes: 36 additions & 0 deletions libraries/lib-cloud-audiocom/sync/CloudSyncUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <numeric>
#include <set>
#include <unordered_set>

#include <rapidjson/document.h>
#include <rapidjson/writer.h>
Expand All @@ -20,6 +21,8 @@

#include <algorithm>

#include "wxFileNameWrapper.h"

namespace cloud::audiocom::sync
{

Expand Down Expand Up @@ -230,4 +233,37 @@ DeserializeProjectResponse(const std::string& data)
return result;
}

namespace
{
wxString SafeName (wxString name)
{
static const std::unordered_set<wxChar> invalidChars {
L'/', L'\\', L':', L'*', L'?', L'"', L'<', L'>', L'|', L'@', L'&'
};

for (size_t i = 0; i < name.length(); ++i)
{
if (invalidChars.find(name[i]) != invalidChars.end())
name[i] = wxT('_');
}

return name;
}
} // namespace

wxString
MakeSafeProjectPath(const wxString& rootDir, const wxString& projectName)
{
const auto safeName = SafeName(projectName);

auto path = wxFileNameWrapper { rootDir, safeName, "aup3" };

int iteration = 0;
while (path.FileExists())
path.SetName(wxString::Format("%s_%d", safeName, ++iteration));


return path.GetFullPath();
}

} // namespace cloud::audiocom::sync
5 changes: 5 additions & 0 deletions libraries/lib-cloud-audiocom/sync/CloudSyncUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <vector>
#include <memory>

#include <wx/string.h>

enum class sampleFormat : unsigned;
class SampleBlock;
using SampleBlockPtr = std::shared_ptr<SampleBlock>;
Expand Down Expand Up @@ -83,4 +85,7 @@ struct ProjectResponse final

std::optional<ProjectResponse> DeserializeProjectResponse(const std::string& data);

wxString
MakeSafeProjectPath(const wxString& rootDir, const wxString& projectName);

} // namespace cloud::audiocom::sync

0 comments on commit ca7df92

Please sign in to comment.