2 * Copyright 2016-2017 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license
6 * Alexander von Gluck IV <kallisti5@unixzen.com>
7 * Brian Hill <supernova@tycho.email>
10 #include "SoftwareUpdaterApp.h"
17 #undef B_TRANSLATION_CONTEXT
18 #define B_TRANSLATION_CONTEXT "SoftwareUpdaterApp"
21 static const char* const kUsage
= B_TRANSLATE_COMMENT(
22 "Usage: SoftwareUpdater <command> [ <option> ]\n"
23 "Updates installed packages.\n"
26 " update - Search repositories for updates on all packages.\n"
27 " check - Check for available updates but only display a "
28 "notification with results.\n"
29 " full-sync - Synchronize the installed packages with the "
33 " -h or --help Print this usage help\n"
34 " -v or --verbose Output verbose information\n",
35 "Command line usage help")
38 static struct option
const kLongOptions
[] = {
39 {"verbose", no_argument
, 0, 'v'},
40 {"help", no_argument
, 0, 'h'},
45 SoftwareUpdaterApp::SoftwareUpdaterApp()
47 BApplication(kAppSignature
),
49 fFinalQuitFlag(false),
50 fActionRequested(UPDATE
),
57 SoftwareUpdaterApp::~SoftwareUpdaterApp()
67 SoftwareUpdaterApp::QuitRequested()
72 // Simulate a cancel request from window- this gives the updater a chance
74 if (fWindowMessenger
.IsValid())
75 fWindowMessenger
.SendMessage(kMsgCancel
);
81 SoftwareUpdaterApp::ReadyToRun()
83 // Argvs no longer accepted once the process starts
84 fArgvsAccepted
= false;
86 fWorker
= new WorkingLooper(fActionRequested
, fVerbose
);
91 SoftwareUpdaterApp::ArgvReceived(int32 argc
, char **argv
)
93 if (!fArgvsAccepted
) {
94 fputs(B_TRANSLATE("Argument variables are no longer accepted\n"),
100 while ((c
= getopt_long(argc
, argv
, "hv", kLongOptions
, NULL
)) != -1) {
105 fputs(kUsage
, stdout
);
112 fputs(kUsage
, stderr
);
118 const char* command
= "";
119 int32 argCount
= argc
- optind
;
122 else if (argCount
> 1) {
123 fputs(kUsage
, stderr
);
126 command
= argv
[optind
];
128 fActionRequested
= USER_SELECTION_NEEDED
;
129 if (strcmp("update", command
) == 0)
130 fActionRequested
= UPDATE
;
131 else if (strcmp("check", command
) == 0)
132 fActionRequested
= UPDATE_CHECK_ONLY
;
133 else if (strcmp("full-sync", command
) == 0)
134 fActionRequested
= FULLSYNC
;
136 fputs(B_TRANSLATE_COMMENT("Unrecognized argument", "Error message"),
138 fprintf(stderr
, " \"%s\"\n", command
);
139 fputs(kUsage
, stderr
);
145 SoftwareUpdaterApp::MessageReceived(BMessage
* message
)
147 switch (message
->what
) {
149 message
->FindMessenger(kKeyMessenger
, &fWindowMessenger
);
153 fFinalQuitFlag
= true;
154 PostMessage(B_QUIT_REQUESTED
);
158 BApplication::MessageReceived(message
);
164 main(int argc
, const char* const* argv
)
166 SoftwareUpdaterApp app
;