source: mainline/uspace/app/nav/verify.c

Last change on this file was 1ec732a, checked in by Jiri Svoboda <jiri@…>, 5 weeks ago

Verify file - navigator operation and command-line utility.

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 * Copyright (c) 2025 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup nav
30 * @{
31 */
32/**
33 * @file Navigator Verify File.
34 */
35
36#include <fmgt.h>
37#include <stdlib.h>
38#include <str_error.h>
39#include <ui/fixed.h>
40#include <ui/filelist.h>
41#include <ui/msgdialog.h>
42#include <ui/resource.h>
43#include <ui/ui.h>
44#include <ui/window.h>
45#include <stdbool.h>
46#include <str.h>
47#include "dlg/progress.h"
48#include "dlg/verifydlg.h"
49#include "menu.h"
50#include "nav.h"
51#include "types/verify.h"
52#include "verify.h"
53
54static void verify_bok(verify_dlg_t *, void *);
55static void verify_bcancel(verify_dlg_t *, void *);
56static void verify_close(verify_dlg_t *, void *);
57
58static verify_dlg_cb_t verify_cb = {
59 .bok = verify_bok,
60 .bcancel = verify_bcancel,
61 .close = verify_close
62};
63
64static bool verify_abort_query(void *);
65static void verify_progress(void *, fmgt_progress_t *);
66
67static fmgt_cb_t verify_fmgt_cb = {
68 .abort_query = verify_abort_query,
69 .io_error_query = navigator_io_error_query,
70 .progress = verify_progress,
71};
72
73/** Open Verify dialog.
74 *
75 * @param navigator Navigator
76 * @param flist File list
77 */
78void navigator_verify_dlg(navigator_t *navigator, fmgt_flist_t *flist)
79{
80 verify_dlg_t *dlg;
81 errno_t rc;
82
83 rc = verify_dlg_create(navigator->ui, flist, &dlg);
84 if (rc != EOK)
85 return;
86
87 verify_dlg_set_cb(dlg, &verify_cb, (void *)navigator);
88}
89
90/** Verify worker function.
91 *
92 * @param arg Argument (navigator_verify_job_t)
93 */
94static void verify_wfunc(void *arg)
95{
96 fmgt_t *fmgt = NULL;
97 navigator_verify_job_t *job = (navigator_verify_job_t *)arg;
98 char *msg = NULL;
99 navigator_t *nav = job->navigator;
100 ui_msg_dialog_t *dialog = NULL;
101 ui_msg_dialog_params_t params;
102 errno_t rc;
103 int rv;
104
105 rc = fmgt_create(&fmgt);
106 if (rc != EOK) {
107 /* out of memory */
108 return;
109 }
110
111 fmgt_set_cb(fmgt, &verify_fmgt_cb, (void *)nav);
112 fmgt_set_init_update(fmgt, true);
113
114 rc = fmgt_verify(fmgt, job->flist);
115 if (rc != EOK) {
116 rv = asprintf(&msg, "Error verifying file(s) (%s).",
117 str_error(rc));
118 if (rv < 0)
119 return;
120 goto error;
121 }
122
123 fmgt_destroy(fmgt);
124 ui_lock(nav->ui);
125 progress_dlg_destroy(nav->progress_dlg);
126 navigator_refresh_panels(nav);
127 ui_unlock(nav->ui);
128 fmgt_flist_destroy(job->flist);
129 free(job);
130 return;
131error:
132 fmgt_destroy(fmgt);
133 ui_lock(nav->ui);
134 progress_dlg_destroy(nav->progress_dlg);
135 navigator_refresh_panels(nav);
136 ui_msg_dialog_params_init(&params);
137 params.caption = "Error";
138 params.text = msg;
139 (void) ui_msg_dialog_create(nav->ui, &params, &dialog);
140 ui_unlock(nav->ui);
141 free(msg);
142}
143
144/** Verify dialog confirmed.
145 *
146 * @param dlg Verify dialog
147 * @param arg Argument (navigator_t *)
148 */
149static void verify_bok(verify_dlg_t *dlg, void *arg)
150{
151 navigator_t *nav = (navigator_t *)arg;
152 ui_msg_dialog_t *dialog = NULL;
153 navigator_verify_job_t *job;
154 ui_msg_dialog_params_t params;
155 progress_dlg_params_t pd_params;
156 char *msg = NULL;
157 errno_t rc;
158
159 verify_dlg_destroy(dlg);
160
161 job = calloc(1, sizeof(navigator_verify_job_t));
162 if (job == NULL)
163 return;
164
165 job->navigator = nav;
166 job->flist = dlg->flist;
167 dlg->flist = NULL;
168
169 progress_dlg_params_init(&pd_params);
170 pd_params.caption = "Verifying";
171
172 rc = progress_dlg_create(nav->ui, &pd_params, &nav->progress_dlg);
173 if (rc != EOK) {
174 msg = str_dup("Out of memory.");
175 if (msg == NULL)
176 return;
177 goto error;
178 }
179
180 progress_dlg_set_cb(nav->progress_dlg, &navigator_progress_cb,
181 (void *)nav);
182
183 rc = navigator_worker_start(nav, verify_wfunc, (void *)job);
184 if (rc != EOK) {
185 msg = str_dup("Out of memory.");
186 if (msg == NULL)
187 return;
188 goto error;
189 }
190
191 return;
192error:
193 ui_msg_dialog_params_init(&params);
194 params.caption = "Error";
195 params.text = msg;
196 (void) ui_msg_dialog_create(nav->ui, &params, &dialog);
197 free(msg);
198}
199
200/** New file dialog cancelled.
201 *
202 * @param dlg New file dialog
203 * @param arg Argument (navigator_t *)
204 */
205static void verify_bcancel(verify_dlg_t *dlg, void *arg)
206{
207 (void)arg;
208 verify_dlg_destroy(dlg);
209}
210
211/** New file dialog closed.
212 *
213 * @param dlg New file dialog
214 * @param arg Argument (navigator_t *)
215 */
216static void verify_close(verify_dlg_t *dlg, void *arg)
217{
218 (void)arg;
219 verify_dlg_destroy(dlg);
220}
221
222/** New file abort query.
223 *
224 * @param arg Argument (navigator_t *)
225 * @return @c true iff abort is requested
226 */
227static bool verify_abort_query(void *arg)
228{
229 navigator_t *nav = (navigator_t *)arg;
230
231 return nav->abort_op;
232}
233
234/** New file progress update.
235 *
236 * @param arg Argument (navigator_t *)
237 * @param progress Progress update
238 */
239static void verify_progress(void *arg, fmgt_progress_t *progress)
240{
241 navigator_t *nav = (navigator_t *)arg;
242
243 progress_dlg_set_progress(nav->progress_dlg, progress);
244}
245
246/** @}
247 */
Note: See TracBrowser for help on using the repository browser.