xref: /aosp_15_r20/external/lzma/CPP/7zip/UI/GUI/UpdateCallbackGUI2.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // UpdateCallbackGUI2.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../FileManager/LangUtils.h"
6 #include "../FileManager/PasswordDialog.h"
7 
8 #include "resource2.h"
9 #include "resource3.h"
10 #include "ExtractRes.h"
11 #include "../FileManager/resourceGui.h"
12 
13 #include "UpdateCallbackGUI.h"
14 
15 using namespace NWindows;
16 
17 static const UINT k_UpdNotifyLangs[] =
18 {
19   IDS_PROGRESS_ADD,
20   IDS_PROGRESS_UPDATE,
21   IDS_PROGRESS_ANALYZE,
22   IDS_PROGRESS_REPLICATE,
23   IDS_PROGRESS_REPACK,
24   IDS_PROGRESS_SKIPPING,
25   IDS_PROGRESS_DELETE,
26   IDS_PROGRESS_HEADER
27 };
28 
Init()29 void CUpdateCallbackGUI2::Init()
30 {
31   NumFiles = 0;
32 
33   LangString(IDS_PROGRESS_REMOVE, _lang_Removing);
34   LangString(IDS_MOVING, _lang_Moving);
35   _lang_Ops.Clear();
36   for (unsigned i = 0; i < Z7_ARRAY_SIZE(k_UpdNotifyLangs); i++)
37     _lang_Ops.Add(LangString(k_UpdNotifyLangs[i]));
38 }
39 
SetOperation_Base(UInt32 notifyOp,const wchar_t * name,bool isDir)40 HRESULT CUpdateCallbackGUI2::SetOperation_Base(UInt32 notifyOp, const wchar_t *name, bool isDir)
41 {
42   const UString *s = NULL;
43   if (notifyOp < _lang_Ops.Size())
44     s = &(_lang_Ops[(unsigned)notifyOp]);
45   else
46     s = &_emptyString;
47 
48   return ProgressDialog->Sync.Set_Status2(*s, name, isDir);
49 }
50 
51 
ShowAskPasswordDialog()52 HRESULT CUpdateCallbackGUI2::ShowAskPasswordDialog()
53 {
54   CPasswordDialog dialog;
55   ProgressDialog->WaitCreating();
56   if (dialog.Create(*ProgressDialog) != IDOK)
57     return E_ABORT;
58   Password = dialog.Password;
59   PasswordIsDefined = true;
60   return S_OK;
61 }
62 
63 
MoveArc_UpdateStatus()64 HRESULT CUpdateCallbackGUI2::MoveArc_UpdateStatus()
65 {
66   UString s;
67   s.Add_UInt64(_arcMoving_percents);
68   s.Add_Char('%');
69 
70   const bool totalDefined = (_arcMoving_total != 0 && _arcMoving_total != (UInt64)(Int64)-1);
71   if (totalDefined || _arcMoving_current != 0)
72   {
73     s += " : ";
74     s.Add_UInt64(_arcMoving_current >> 20);
75     s += " MiB";
76   }
77   if (totalDefined)
78   {
79     s += " / ";
80     s.Add_UInt64((_arcMoving_total + ((1 << 20) - 1)) >> 20);
81     s += " MiB";
82   }
83 
84   s += " : ";
85   s += _lang_Moving;
86   s += " : ";
87   // s.Add_Char('\"');
88   s += _arcMoving_name1;
89   // s.Add_Char('\"');
90   return ProgressDialog->Sync.Set_Status2(s, _arcMoving_name2,
91       false); // isDir
92 }
93 
94 
MoveArc_Start_Base(const wchar_t * srcTempPath,const wchar_t * destFinalPath,UInt64 totalSize,Int32 updateMode)95 HRESULT CUpdateCallbackGUI2::MoveArc_Start_Base(const wchar_t *srcTempPath, const wchar_t *destFinalPath, UInt64 totalSize, Int32 updateMode)
96 {
97   _arcMoving_percents = 0;
98   _arcMoving_total = totalSize;
99   _arcMoving_current = 0;
100   _arcMoving_updateMode = updateMode;
101   _arcMoving_name1 = srcTempPath;
102   _arcMoving_name2 = destFinalPath;
103   return MoveArc_UpdateStatus();
104 }
105 
106 
MoveArc_Progress_Base(UInt64 totalSize,UInt64 currentSize)107 HRESULT CUpdateCallbackGUI2::MoveArc_Progress_Base(UInt64 totalSize, UInt64 currentSize)
108 {
109   _arcMoving_total = totalSize;
110   _arcMoving_current = currentSize;
111   UInt64 percents = 0;
112   if (totalSize != 0)
113   {
114     if (totalSize < ((UInt64)1 << 57))
115       percents = currentSize * 100 / totalSize;
116     else
117       percents = currentSize / (totalSize / 100);
118   }
119   if (percents == _arcMoving_percents)
120     return ProgressDialog->Sync.CheckStop();
121   // Sleep(300); // for debug
122   _arcMoving_percents = percents;
123   return MoveArc_UpdateStatus();
124 }
125 
126 
MoveArc_Finish_Base()127 HRESULT CUpdateCallbackGUI2::MoveArc_Finish_Base()
128 {
129   return ProgressDialog->Sync.Set_Status2(L"", L"", false);
130 }
131