[RAPPS] rename snapshot to screenshot, filename to location (#2939)

This commit is contained in:
He Yang 2020-06-22 00:20:45 +08:00 committed by Mark Jansen
parent cfb0963c1f
commit e636373016
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
3 changed files with 79 additions and 79 deletions

View file

@ -54,32 +54,32 @@ VOID CAvailableApplicationInfo::RetrieveGeneralInfo(AvailableStrings& AvlbString
GetString(L"URLSite", m_szUrlSite); GetString(L"URLSite", m_szUrlSite);
GetString(L"SHA1", m_szSHA1); GetString(L"SHA1", m_szSHA1);
static_assert(MAX_SNAPSHOT_NUM < 10000, "MAX_SNAPSHOT_NUM is too big"); static_assert(MAX_SCRNSHOT_NUM < 10000, "MAX_SCRNSHOT_NUM is too big");
for (int i = 0; i < MAX_SNAPSHOT_NUM; i++) for (int i = 0; i < MAX_SCRNSHOT_NUM; i++)
{ {
WCHAR SnapshotField[sizeof("Snapshot") + 4]; CStringW ScrnshotField;
wsprintfW(SnapshotField, L"Snapshot%d", i + 1); ScrnshotField.Format(L"Screenshot%d", i + 1);
ATL::CStringW SnapshotLocation; CStringW ScrnshotLocation;
if (!GetString(SnapshotField, SnapshotLocation)) if (!GetString(ScrnshotField, ScrnshotLocation))
{ {
continue; continue;
} }
if (PathIsURLW(SnapshotLocation.GetString())) if (PathIsURLW(ScrnshotLocation.GetString()))
{ {
m_szSnapshotLocation.Add(SnapshotLocation); m_szScrnshotLocation.Add(ScrnshotLocation);
} }
else else
{ {
// TODO: Does the filename contain anything stuff like "\\" ".." ":" "<" ">" ? // TODO: Does the filename contain anything stuff like "\\" ".." ":" "<" ">" ?
// these stuff may lead to security issues // these stuff may lead to security issues
ATL::CStringW SnapshotName = AvlbStrings.szAppsPath; ATL::CStringW ScrnshotName = AvlbStrings.szAppsPath;
PathAppendW(SnapshotName.GetBuffer(MAX_PATH), L"snapshots"); PathAppendW(ScrnshotName.GetBuffer(MAX_PATH), L"screenshots");
PathAppendW(SnapshotName.GetBuffer(), SnapshotLocation.GetString()); PathAppendW(ScrnshotName.GetBuffer(), ScrnshotLocation.GetString());
SnapshotName.ReleaseBuffer(); ScrnshotName.ReleaseBuffer();
m_szSnapshotLocation.Add(SnapshotName); m_szScrnshotLocation.Add(ScrnshotName);
} }
} }
@ -236,13 +236,13 @@ BOOL CAvailableApplicationInfo::HasUpdate() const
return (m_szInstalledVersion.Compare(m_szVersion) < 0) ? TRUE : FALSE; return (m_szInstalledVersion.Compare(m_szVersion) < 0) ? TRUE : FALSE;
} }
BOOL CAvailableApplicationInfo::RetrieveSnapshot(UINT Index,ATL::CStringW& SnapshotFileName) const BOOL CAvailableApplicationInfo::RetrieveScrnshot(UINT Index,ATL::CStringW& ScrnshotLocation) const
{ {
if (Index >= (UINT)m_szSnapshotLocation.GetSize()) if (Index >= (UINT)m_szScrnshotLocation.GetSize())
{ {
return FALSE; return FALSE;
} }
SnapshotFileName = m_szSnapshotLocation[Index]; ScrnshotLocation = m_szScrnshotLocation[Index];
return TRUE; return TRUE;
} }

View file

@ -35,10 +35,10 @@ using namespace Gdiplus;
// default broken-image icon size // default broken-image icon size
#define BROKENIMG_ICON_SIZE 96 #define BROKENIMG_ICON_SIZE 96
// the boundary of w/h ratio of snapshot preview window // the boundary of w/h ratio of scrnshot preview window
#define SNPSHT_MAX_ASPECT_RAT 2.5 #define SCRNSHOT_MAX_ASPECT_RAT 2.5
// padding between snapshot preview and richedit (in pixel) // padding between scrnshot preview and richedit (in pixel)
#define INFO_DISPLAY_PADDING 10 #define INFO_DISPLAY_PADDING 10
// minimum width of richedit // minimum width of richedit
@ -46,15 +46,15 @@ using namespace Gdiplus;
// user-defined window message // user-defined window message
#define WM_RAPPS_DOWNLOAD_COMPLETE (WM_USER + 1) // notify download complete. wParam is error code, and lParam is a pointer to SnapshotDownloadParam #define WM_RAPPS_DOWNLOAD_COMPLETE (WM_USER + 1) // notify download complete. wParam is error code, and lParam is a pointer to ScrnshotDownloadParam
#define WM_RAPPS_RESIZE_CHILDREN (WM_USER + 2) // ask parent window to resize children. #define WM_RAPPS_RESIZE_CHILDREN (WM_USER + 2) // ask parent window to resize children.
enum SNPSHT_STATUS enum SCRNSHOT_STATUS
{ {
SNPSHTPREV_EMPTY, // show nothing SCRNSHOT_PREV_EMPTY, // show nothing
SNPSHTPREV_LOADING, // image is loading (most likely downloading) SCRNSHOT_PREV_LOADING, // image is loading (most likely downloading)
SNPSHTPREV_IMAGE, // display image from a file SCRNSHOT_PREV_IMAGE, // display image from a file
SNPSHTPREV_FAILED // image can not be shown (download failure or wrong image) SCRNSHOT_PREV_FAILED // image can not be shown (download failure or wrong image)
}; };
#define TIMER_LOADING_ANIMATION 1 // Timer ID #define TIMER_LOADING_ANIMATION 1 // Timer ID
@ -65,13 +65,13 @@ enum SNPSHT_STATUS
#define PI 3.1415927 #define PI 3.1415927
typedef struct __SnapshotDownloadParam typedef struct __ScrnshotDownloadParam
{ {
LONGLONG ID; LONGLONG ID;
HANDLE hFile; HANDLE hFile;
HWND hwndNotify; HWND hwndNotify;
ATL::CStringW DownloadFileName; ATL::CStringW DownloadFileName;
} SnapshotDownloadParam; } ScrnshotDownloadParam;
INT GetSystemColorDepth() INT GetSystemColorDepth()
{ {
@ -304,7 +304,7 @@ public:
} }
}; };
int SnapshotDownloadCallback( int ScrnshotDownloadCallback(
pASYNCINET AsyncInet, pASYNCINET AsyncInet,
ASYNC_EVENT Event, ASYNC_EVENT Event,
WPARAM wParam, WPARAM wParam,
@ -312,7 +312,7 @@ int SnapshotDownloadCallback(
VOID* Extension VOID* Extension
) )
{ {
SnapshotDownloadParam* DownloadParam = (SnapshotDownloadParam*)Extension; ScrnshotDownloadParam* DownloadParam = (ScrnshotDownloadParam*)Extension;
switch (Event) switch (Event)
{ {
case ASYNCINET_DATA: case ASYNCINET_DATA:
@ -338,12 +338,12 @@ int SnapshotDownloadCallback(
return 0; return 0;
} }
class CAppSnapshotPreview : class CAppScrnshotPreview :
public CWindowImpl<CAppSnapshotPreview> public CWindowImpl<CAppScrnshotPreview>
{ {
private: private:
SNPSHT_STATUS SnpshtPrevStauts = SNPSHTPREV_EMPTY; SCRNSHOT_STATUS ScrnshotPrevStauts = SCRNSHOT_PREV_EMPTY;
Image* pImage = NULL; Image* pImage = NULL;
HICON hBrokenImgIcon = NULL; HICON hBrokenImgIcon = NULL;
BOOL bLoadingTimerOn = FALSE; BOOL bLoadingTimerOn = FALSE;
@ -377,7 +377,7 @@ private:
} }
case WM_RAPPS_DOWNLOAD_COMPLETE: case WM_RAPPS_DOWNLOAD_COMPLETE:
{ {
SnapshotDownloadParam* DownloadParam = (SnapshotDownloadParam*)lParam; ScrnshotDownloadParam* DownloadParam = (ScrnshotDownloadParam*)lParam;
AsyncInetRelease(AsyncInet); AsyncInetRelease(AsyncInet);
AsyncInet = NULL; AsyncInet = NULL;
switch (wParam) switch (wParam)
@ -477,7 +477,7 @@ private:
VOID DisplayLoading() VOID DisplayLoading()
{ {
SetStatus(SNPSHTPREV_LOADING); SetStatus(SCRNSHOT_PREV_LOADING);
if (bLoadingTimerOn) if (bLoadingTimerOn)
{ {
KillTimer(TIMER_LOADING_ANIMATION); KillTimer(TIMER_LOADING_ANIMATION);
@ -490,14 +490,14 @@ private:
VOID DisplayFailed() VOID DisplayFailed()
{ {
InterlockedIncrement64(&ContentID); InterlockedIncrement64(&ContentID);
SetStatus(SNPSHTPREV_FAILED); SetStatus(SCRNSHOT_PREV_FAILED);
PreviousDisplayCleanup(); PreviousDisplayCleanup();
} }
BOOL DisplayFile(LPCWSTR lpszFileName) BOOL DisplayFile(LPCWSTR lpszFileName)
{ {
PreviousDisplayCleanup(); PreviousDisplayCleanup();
SetStatus(SNPSHTPREV_IMAGE); SetStatus(SCRNSHOT_PREV_IMAGE);
pImage = Bitmap::FromFile(lpszFileName, 0); pImage = Bitmap::FromFile(lpszFileName, 0);
if (pImage->GetLastStatus() != Ok) if (pImage->GetLastStatus() != Ok)
{ {
@ -507,9 +507,9 @@ private:
return TRUE; return TRUE;
} }
VOID SetStatus(SNPSHT_STATUS Status) VOID SetStatus(SCRNSHOT_STATUS Status)
{ {
SnpshtPrevStauts = Status; ScrnshotPrevStauts = Status;
} }
VOID PaintOnDC(HDC hdc, int width, int height, BOOL bDrawBkgnd) VOID PaintOnDC(HDC hdc, int width, int height, BOOL bDrawBkgnd)
@ -526,15 +526,15 @@ private:
SelectObject(hdcMem, hOldBrush); SelectObject(hdcMem, hOldBrush);
} }
switch (SnpshtPrevStauts) switch (ScrnshotPrevStauts)
{ {
case SNPSHTPREV_EMPTY: case SCRNSHOT_PREV_EMPTY:
{ {
} }
break; break;
case SNPSHTPREV_LOADING: case SCRNSHOT_PREV_LOADING:
{ {
Graphics graphics(hdcMem); Graphics graphics(hdcMem);
Color color(255, 0, 0); Color color(255, 0, 0);
@ -564,7 +564,7 @@ private:
} }
break; break;
case SNPSHTPREV_IMAGE: case SCRNSHOT_PREV_IMAGE:
{ {
if (pImage) if (pImage)
{ {
@ -581,7 +581,7 @@ private:
} }
break; break;
case SNPSHTPREV_FAILED: case SCRNSHOT_PREV_FAILED:
{ {
DrawIconEx(hdcMem, DrawIconEx(hdcMem,
(width - BrokenImgSize) / 2, (width - BrokenImgSize) / 2,
@ -632,7 +632,7 @@ public:
LoadCursorW(NULL, IDC_ARROW), LoadCursorW(NULL, IDC_ARROW),
(HBRUSH)(COLOR_BTNFACE + 1), (HBRUSH)(COLOR_BTNFACE + 1),
0, 0,
L"RAppsSnapshotPreview", L"RAppsScrnshotPreview",
NULL NULL
}, },
NULL, NULL, IDC_ARROW, TRUE, 0, _T("") NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
@ -674,7 +674,7 @@ public:
VOID DisplayEmpty() VOID DisplayEmpty()
{ {
InterlockedIncrement64(&ContentID); InterlockedIncrement64(&ContentID);
SetStatus(SNPSHTPREV_EMPTY); SetStatus(SCRNSHOT_PREV_EMPTY);
PreviousDisplayCleanup(); PreviousDisplayCleanup();
} }
@ -687,22 +687,22 @@ public:
{ {
DisplayLoading(); DisplayLoading();
SnapshotDownloadParam* DownloadParam = new SnapshotDownloadParam; ScrnshotDownloadParam* DownloadParam = new ScrnshotDownloadParam;
if (!DownloadParam) return FALSE; if (!DownloadParam) return FALSE;
DownloadParam->hwndNotify = m_hWnd; DownloadParam->hwndNotify = m_hWnd;
DownloadParam->ID = ID; DownloadParam->ID = ID;
// generate a filename // generate a filename
ATL::CStringW SnapshotFolder = CAvailableApps::m_Strings.szAppsPath; ATL::CStringW ScrnshotFolder = CAvailableApps::m_Strings.szAppsPath;
PathAppendW(SnapshotFolder.GetBuffer(MAX_PATH), L"snapshots"); PathAppendW(ScrnshotFolder.GetBuffer(MAX_PATH), L"screenshots");
SnapshotFolder.ReleaseBuffer(); ScrnshotFolder.ReleaseBuffer();
if (!PathIsDirectoryW(SnapshotFolder.GetString())) if (!PathIsDirectoryW(ScrnshotFolder.GetString()))
{ {
CreateDirectoryW(SnapshotFolder.GetString(), NULL); CreateDirectoryW(ScrnshotFolder.GetString(), NULL);
} }
if (!GetTempFileNameW(SnapshotFolder.GetString(), L"img", if (!GetTempFileNameW(ScrnshotFolder.GetString(), L"img",
0, DownloadParam->DownloadFileName.GetBuffer(MAX_PATH))) 0, DownloadParam->DownloadFileName.GetBuffer(MAX_PATH)))
{ {
DownloadParam->DownloadFileName.ReleaseBuffer(); DownloadParam->DownloadFileName.ReleaseBuffer();
@ -721,7 +721,7 @@ public:
return FALSE; return FALSE;
} }
AsyncInet = AsyncInetDownload(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, lpszLocation, TRUE, SnapshotDownloadCallback, DownloadParam); AsyncInet = AsyncInetDownload(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, lpszLocation, TRUE, ScrnshotDownloadCallback, DownloadParam);
if (!AsyncInet) if (!AsyncInet)
{ {
CloseHandle(DownloadParam->hFile); CloseHandle(DownloadParam->hFile);
@ -740,29 +740,29 @@ public:
int GetRequestedWidth(int Height) // calculate requested window width by given height int GetRequestedWidth(int Height) // calculate requested window width by given height
{ {
switch (SnpshtPrevStauts) switch (ScrnshotPrevStauts)
{ {
case SNPSHTPREV_EMPTY: case SCRNSHOT_PREV_EMPTY:
return 0; return 0;
case SNPSHTPREV_LOADING: case SCRNSHOT_PREV_LOADING:
return 200; return 200;
case SNPSHTPREV_IMAGE: case SCRNSHOT_PREV_IMAGE:
if (pImage) if (pImage)
{ {
// return the width needed to display image inside the window. // return the width needed to display image inside the window.
// and always keep window w/h ratio inside [ 1/SNPSHT_MAX_ASPECT_RAT, SNPSHT_MAX_ASPECT_RAT ] // and always keep window w/h ratio inside [ 1/SCRNSHOT_MAX_ASPECT_RAT, SCRNSHOT_MAX_ASPECT_RAT ]
return (int)floor((float)Height * return (int)floor((float)Height *
max(min((float)pImage->GetWidth() / (float)pImage->GetHeight(), (float)SNPSHT_MAX_ASPECT_RAT), 1.0/ (float)SNPSHT_MAX_ASPECT_RAT)); max(min((float)pImage->GetWidth() / (float)pImage->GetHeight(), (float)SCRNSHOT_MAX_ASPECT_RAT), 1.0/ (float)SCRNSHOT_MAX_ASPECT_RAT));
} }
return 0; return 0;
case SNPSHTPREV_FAILED: case SCRNSHOT_PREV_FAILED:
return 200; return 200;
default: default:
return 0; return 0;
} }
} }
~CAppSnapshotPreview() ~CAppScrnshotPreview()
{ {
PreviousDisplayCleanup(); PreviousDisplayCleanup();
} }
@ -784,8 +784,8 @@ private:
RichEdit = new CAppRichEdit(); RichEdit = new CAppRichEdit();
RichEdit->Create(hwnd); RichEdit->Create(hwnd);
SnpshtPrev = new CAppSnapshotPreview(); ScrnshotPrev = new CAppScrnshotPreview();
SnpshtPrev->Create(hwnd); ScrnshotPrev->Create(hwnd);
break; break;
} }
case WM_SIZE: case WM_SIZE:
@ -831,23 +831,23 @@ private:
VOID ResizeChildren(int Width, int Height) VOID ResizeChildren(int Width, int Height)
{ {
int SnpshtWidth = SnpshtPrev->GetRequestedWidth(Height); int ScrnshotWidth = ScrnshotPrev->GetRequestedWidth(Height);
// make sure richedit always have room to display // make sure richedit always have room to display
SnpshtWidth = min(SnpshtWidth, Width - INFO_DISPLAY_PADDING - RICHEDIT_MIN_WIDTH); ScrnshotWidth = min(ScrnshotWidth, Width - INFO_DISPLAY_PADDING - RICHEDIT_MIN_WIDTH);
DWORD dwError = ERROR_SUCCESS; DWORD dwError = ERROR_SUCCESS;
HDWP hDwp = BeginDeferWindowPos(2); HDWP hDwp = BeginDeferWindowPos(2);
if (hDwp) if (hDwp)
{ {
hDwp = ::DeferWindowPos(hDwp, SnpshtPrev->m_hWnd, NULL, hDwp = ::DeferWindowPos(hDwp, ScrnshotPrev->m_hWnd, NULL,
0, 0, SnpshtWidth, Height, 0); 0, 0, ScrnshotWidth, Height, 0);
if (hDwp) if (hDwp)
{ {
// hide the padding if snapshot window width == 0 // hide the padding if scrnshot window width == 0
int RicheditPosX = SnpshtWidth ? (SnpshtWidth + INFO_DISPLAY_PADDING) : 0; int RicheditPosX = ScrnshotWidth ? (ScrnshotWidth + INFO_DISPLAY_PADDING) : 0;
hDwp = ::DeferWindowPos(hDwp, RichEdit->m_hWnd, NULL, hDwp = ::DeferWindowPos(hDwp, RichEdit->m_hWnd, NULL,
RicheditPosX, 0, Width - RicheditPosX, Height, 0); RicheditPosX, 0, Width - RicheditPosX, Height, 0);
@ -909,7 +909,7 @@ private:
public: public:
CAppRichEdit * RichEdit; CAppRichEdit * RichEdit;
CAppSnapshotPreview * SnpshtPrev; CAppScrnshotPreview * ScrnshotPrev;
static ATL::CWndClassInfo& GetWndClassInfo() static ATL::CWndClassInfo& GetWndClassInfo()
{ {
@ -944,14 +944,14 @@ public:
BOOL ShowAvailableAppInfo(CAvailableApplicationInfo* Info) BOOL ShowAvailableAppInfo(CAvailableApplicationInfo* Info)
{ {
ATL::CStringW SnapshotLocation; ATL::CStringW ScrnshotLocation;
if (Info->RetrieveSnapshot(0, SnapshotLocation)) if (Info->RetrieveScrnshot(0, ScrnshotLocation))
{ {
SnpshtPrev->DisplayImage(SnapshotLocation); ScrnshotPrev->DisplayImage(ScrnshotLocation);
} }
else else
{ {
SnpshtPrev->DisplayEmpty(); ScrnshotPrev->DisplayEmpty();
} }
ResizeChildren(); ResizeChildren();
return RichEdit->ShowAvailableAppInfo(Info); return RichEdit->ShowAvailableAppInfo(Info);
@ -959,14 +959,14 @@ public:
BOOL ShowInstalledAppInfo(PINSTALLED_INFO Info) BOOL ShowInstalledAppInfo(PINSTALLED_INFO Info)
{ {
SnpshtPrev->DisplayEmpty(); ScrnshotPrev->DisplayEmpty();
ResizeChildren(); ResizeChildren();
return RichEdit->ShowInstalledAppInfo(Info); return RichEdit->ShowInstalledAppInfo(Info);
} }
VOID SetWelcomeText() VOID SetWelcomeText()
{ {
SnpshtPrev->DisplayEmpty(); ScrnshotPrev->DisplayEmpty();
ResizeChildren(); ResizeChildren();
RichEdit->SetWelcomeText(); RichEdit->SetWelcomeText();
} }

View file

@ -8,7 +8,7 @@
#include "misc.h" #include "misc.h"
#define MAX_SNAPSHOT_NUM 16 #define MAX_SCRNSHOT_NUM 16
enum LicenseType enum LicenseType
{ {
@ -51,7 +51,7 @@ struct CAvailableApplicationInfo
ATL::CStringW m_szUrlSite; ATL::CStringW m_szUrlSite;
ATL::CStringW m_szUrlDownload; ATL::CStringW m_szUrlDownload;
ATL::CSimpleArray<LCID> m_LanguageLCIDs; ATL::CSimpleArray<LCID> m_LanguageLCIDs;
ATL::CSimpleArray<ATL::CStringW> m_szSnapshotLocation; ATL::CSimpleArray<ATL::CStringW> m_szScrnshotLocation;
ULONG m_SizeBytes; ULONG m_SizeBytes;
@ -74,7 +74,7 @@ struct CAvailableApplicationInfo
BOOL IsInstalled() const; BOOL IsInstalled() const;
BOOL HasInstalledVersion() const; BOOL HasInstalledVersion() const;
BOOL HasUpdate() const; BOOL HasUpdate() const;
BOOL RetrieveSnapshot(UINT Index, ATL::CStringW& SnapshotFileName) const; BOOL RetrieveScrnshot(UINT Index, ATL::CStringW& ScrnshotLocation) const;
// Set a timestamp // Set a timestamp
VOID SetLastWriteTime(FILETIME* ftTime); VOID SetLastWriteTime(FILETIME* ftTime);