Use $HOME rather than hard-coded user name.
[dcpomatic.git] / src / tools / dcpomatic_disk.cc
index d3235c1bbc1d7c2ad7db1e189b574f6083d816bc..395b60a8857f83866d7b29bb86c4327c6196d5f6 100644 (file)
@@ -22,6 +22,7 @@
 #include "wx/disk_warning_dialog.h"
 #include "wx/drive_wipe_warning_dialog.h"
 #include "wx/editable_list.h"
+#include "wx/id.h"
 #include "wx/job_manager_view.h"
 #include "wx/message_dialog.h"
 #include "wx/try_unmount_dialog.h"
@@ -39,6 +40,7 @@
 #include "lib/signal_manager.h"
 #include "lib/util.h"
 #include "lib/version.h"
+#include <dcp/filesystem.h>
 #include <dcp/warnings.h>
 #include <wx/cmdline.h>
 #include <wx/wx.h>
@@ -68,7 +70,7 @@ using namespace boost::placeholders;
 
 #ifdef DCPOMATIC_OSX
 enum {
-       ID_tools_uninstall = 1,
+       ID_tools_uninstall = DCPOMATIC_MAIN_MENU,
 };
 #endif
 
@@ -85,7 +87,7 @@ public:
        boost::optional<boost::filesystem::path> get () const
        {
                auto const dcp = boost::filesystem::path(wx_to_std(GetPath()));
-               if (!boost::filesystem::exists(dcp / "ASSETMAP") && !boost::filesystem::exists(dcp / "ASSETMAP.xml")) {
+               if (!dcp::filesystem::exists(dcp / "ASSETMAP") && !dcp::filesystem::exists(dcp / "ASSETMAP.xml")) {
                        error_dialog (nullptr, _("No ASSETMAP or ASSETMAP.xml found in this folder.  Please choose a DCP folder."));
                        return {};
                }
@@ -249,16 +251,14 @@ private:
                        return true;
                }
 
-               auto d = new wxMessageDialog (
-                       0,
+               auto d = make_wx<wxMessageDialog>(
+                       nullptr,
                        _("There are unfinished jobs; are you sure you want to quit?"),
                        _("Unfinished jobs"),
                        wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION
                        );
 
-               bool const r = d->ShowModal() == wxID_YES;
-               d->Destroy ();
-               return r;
+               return d->ShowModal() == wxID_YES;
        }
 
 
@@ -286,11 +286,11 @@ private:
 
                auto ping = [this](int attempt) {
                        if (_nanomsg.send(DISK_WRITER_PING "\n", 1000)) {
-                               auto reply = _nanomsg.receive (1000);
-                               if (reply && *reply == DISK_WRITER_PONG) {
+                               auto reply = DiskWriterBackEndResponse::read_from_nanomsg(_nanomsg, 1000);
+                               if (reply && reply->type() == DiskWriterBackEndResponse::Type::PONG) {
                                        return true;
                                } else if (reply) {
-                                       LOG_DISK("Unexpected response %1 to ping received (attempt %2)", *reply, attempt);
+                                       LOG_DISK("Unexpected response %1 to ping received (attempt %2)", static_cast<int>(reply->type()), attempt);
                                } else {
                                        LOG_DISK("No reply received from ping (attempt %1)", attempt);
                                }
@@ -311,22 +311,20 @@ private:
 
                if (!have_writer) {
 #if defined(DCPOMATIC_WINDOWS)
-                       auto m = new MessageDialog (
+                       auto m = make_wx<MessageDialog>(
                                this,
                                _("DCP-o-matic Disk Writer"),
                                _("Do you see a 'User Account Control' dialogue asking about dcpomatic2_disk_writer.exe?  If so, click 'Yes', then try again.")
                                );
                        m->ShowModal ();
-                       m->Destroy ();
                        return;
 #elif defined(DCPOMATIC_OSX)
-                       auto m = new MessageDialog (
+                       auto m = make_wx<MessageDialog>(
                                this,
                                _("DCP-o-matic Disk Writer"),
                                _("Did you install the DCP-o-matic Disk Writer.pkg from the .dmg?  Please check and try again.")
                                );
                        m->ShowModal ();
-                       m->Destroy ();
                        return;
 #else
                        LOG_DISK_NC ("Failed to ping writer");
@@ -336,9 +334,8 @@ private:
 
                auto const& drive = _drives[_drive->GetSelection()];
                if (drive.mounted()) {
-                       auto d = new TryUnmountDialog(this, drive.description());
+                       auto d = make_wx<TryUnmountDialog>(this, drive.description());
                        int const r = d->ShowModal ();
-                       d->Destroy ();
                        if (r != wxID_OK) {
                                return;
                        }
@@ -353,15 +350,18 @@ private:
                                throw CommunicationFailedError ();
                        }
                        /* The reply may have to wait for the user to authenticate, so let's wait a while */
-                       auto reply = _nanomsg.receive (30000);
-                       if (!reply || *reply != DISK_WRITER_OK) {
-                               auto * m = new MessageDialog (
+                       auto const reply = DiskWriterBackEndResponse::read_from_nanomsg(_nanomsg, 30000);
+                       if (!reply || reply->type() != DiskWriterBackEndResponse::Type::OK) {
+                               auto m = make_wx<MessageDialog>(
                                                this,
                                                _("DCP-o-matic Disk Writer"),
-                                               wxString::Format(_("The drive %s could not be unmounted.\nClose any application that is using it, then try again."), std_to_wx(drive.description()))
+                                               wxString::Format(
+                                                       _("The drive %s could not be unmounted.\nClose any application that is using it, then try again. (%s)"),
+                                                       std_to_wx(drive.description()),
+                                                       reply->error_message()
+                                                       )
                                                );
                                m->ShowModal ();
-                               m->Destroy ();
                                return;
                        }
                }