Skip to content

Commit

Permalink
Traktor: Clone data streams when cloning instances in DatabaseView.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 27, 2024
1 parent 6e84401 commit 40364e2
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion code/Editor/App/DatabaseView.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* TRAKTOR
* Copyright (c) 2022-2023 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Core/Io/FileSystem.h"
#include "Core/Io/Path.h"
#include "Core/Io/StreamCopy.h"
#include "Core/Log/Log.h"
#include "Core/Misc/SafeDestroy.h"
#include "Core/Misc/String.h"
Expand Down Expand Up @@ -751,6 +752,31 @@ bool DatabaseView::handleCommand(const ui::Command& command)

instanceClone->setObject(object);

AlignedVector< std::wstring > dataNames;
instance->getDataNames(dataNames);
for (const std::wstring& dataName : dataNames)
{
Ref< IStream > stream = instance->readData(dataName);
if (!stream)
{
log::error << L"Unable to create clone instance; failed to read data." << Endl;
return false;
}

Ref< IStream > cloneStream = instanceClone->writeData(dataName);
if (!cloneStream)
{
log::error << L"Unable to create clone instance; failed to write data." << Endl;
return false;
}

if (!StreamCopy(cloneStream, stream).execute())
{
log::error << L"Unable to create clone instance; failed to copy data." << Endl;
return false;
}
}

if (!instanceClone->commit())
{
log::error << L"Unable to commit clone instance." << Endl;
Expand Down

0 comments on commit 40364e2

Please sign in to comment.