浏览代码

Reporting first run date and package name when checking for application updates + Enforcing check for 3rd party packages + Store installations can display messages from updates check too

Source commit: c5dcb70f2b871e7bfe18662a71f7692d689bd632
Martin Prikryl 3 年之前
父节点
当前提交
ce65d95fa7

+ 13 - 0
source/core/Common.cpp

@@ -17,6 +17,7 @@
 #include <tlhelp32.h>
 #include <tlhelp32.h>
 #include <psapi.h>
 #include <psapi.h>
 #include <CoreMain.h>
 #include <CoreMain.h>
+#include <SessionInfo.h>
 #include <openssl/pkcs12.h>
 #include <openssl/pkcs12.h>
 #include <openssl/pem.h>
 #include <openssl/pem.h>
 #include <openssl/err.h>
 #include <openssl/err.h>
@@ -39,6 +40,7 @@ const UnicodeString LocalInvalidChars(TraceInitStr(L"/\\:*?\"<>|"));
 const UnicodeString PasswordMask(TraceInitStr(L"***"));
 const UnicodeString PasswordMask(TraceInitStr(L"***"));
 const UnicodeString Ellipsis(TraceInitStr(L"..."));
 const UnicodeString Ellipsis(TraceInitStr(L"..."));
 const UnicodeString TitleSeparator(TraceInitStr(L" \u2013 ")); // En-Dash
 const UnicodeString TitleSeparator(TraceInitStr(L" \u2013 ")); // En-Dash
+const UnicodeString OfficialPackage(TraceInitStr(L"MartinPikryl.WinSCP_tvv458r3h9r5m"));
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 UnicodeString ReplaceChar(UnicodeString Str, wchar_t A, wchar_t B)
 UnicodeString ReplaceChar(UnicodeString Str, wchar_t A, wchar_t B)
 {
 {
@@ -3070,6 +3072,7 @@ static void NeedUWPData()
         (GetCurrentPackageFamilyName(&NameLen, NULL) == ERROR_INSUFFICIENT_BUFFER))
         (GetCurrentPackageFamilyName(&NameLen, NULL) == ERROR_INSUFFICIENT_BUFFER))
     {
     {
       GIsUWP = 1;
       GIsUWP = 1;
+      AppLog(L"Is UWP application");
       GPackageName.SetLength(NameLen);
       GPackageName.SetLength(NameLen);
       if (GetCurrentPackageFamilyName(&NameLen, GPackageName.c_str()) == ERROR_SUCCESS)
       if (GetCurrentPackageFamilyName(&NameLen, GPackageName.c_str()) == ERROR_SUCCESS)
       {
       {
@@ -3079,6 +3082,11 @@ static void NeedUWPData()
       {
       {
         GPackageName = L"err";
         GPackageName = L"err";
       }
       }
+      AppLogFmt(L"Package name: %s", (GPackageName));
+    }
+    else
+    {
+      AppLog(L"Is not UWP application");
     }
     }
   }
   }
 }
 }
@@ -3095,6 +3103,11 @@ UnicodeString GetPackageName()
   return GPackageName;
   return GPackageName;
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
+bool IsOfficialPackage()
+{
+  return (GetPackageName() == OfficialPackage);
+}
+//---------------------------------------------------------------------------
 LCID __fastcall GetDefaultLCID()
 LCID __fastcall GetDefaultLCID()
 {
 {
   return GetUserDefaultLCID();
   return GetUserDefaultLCID();

+ 1 - 0
source/core/Common.h

@@ -147,6 +147,7 @@ bool IsWin11();
 bool __fastcall IsWine();
 bool __fastcall IsWine();
 bool __fastcall IsUWP();
 bool __fastcall IsUWP();
 UnicodeString GetPackageName();
 UnicodeString GetPackageName();
+bool IsOfficialPackage();
 TLibModule * __fastcall FindModule(void * Instance);
 TLibModule * __fastcall FindModule(void * Instance);
 __int64 __fastcall Round(double Number);
 __int64 __fastcall Round(double Number);
 bool __fastcall TryRelativeStrToDateTime(UnicodeString S, TDateTime & DateTime, bool Add);
 bool __fastcall TryRelativeStrToDateTime(UnicodeString S, TDateTime & DateTime, bool Add);

+ 26 - 6
source/forms/CustomScpExplorer.cpp

@@ -999,6 +999,7 @@ void TCustomScpExplorerForm::CheckStoreTransition()
   else if ((WinConfiguration->StoreTransition == stStandard) && IsUWP())
   else if ((WinConfiguration->StoreTransition == stStandard) && IsUWP())
   {
   {
     WinConfiguration->StoreTransition = stStoreMigrated;
     WinConfiguration->StoreTransition = stStoreMigrated;
+    WinConfiguration->FirstRun = WinConfiguration->FirstRun + L"=>" + StandardDatestamp();
     AppLog(L"Standard installation migrated to store installation");
     AppLog(L"Standard installation migrated to store installation");
   }
   }
 
 
@@ -9148,40 +9149,59 @@ void __fastcall TCustomScpExplorerForm::StartUpdates()
   // first run after installation
   // first run after installation
   if (double(Updates.LastCheck) == 0)
   if (double(Updates.LastCheck) == 0)
   {
   {
+    AppLog(L"First run, scheduling updates check for the next run");
     // make sure next time there will be an update (if enabled)
     // make sure next time there will be an update (if enabled)
     Updates.LastCheck = TDateTime(1);
     Updates.LastCheck = TDateTime(1);
     WinConfiguration->Updates = Updates;
     WinConfiguration->Updates = Updates;
   }
   }
-  else if ((double(Updates.Period) > 0) &&
-           (Now() - Updates.LastCheck >= Updates.Period))
+  else
   {
   {
-    TThreadMethod OnUpdatesChecked = NULL;
-    if (!IsUWP())
+    TDateTime Period;
+    if (IsUWP() && !IsOfficialPackage())
+    {
+      Period = DefaultUpdatesPeriod;
+      AppLog(L"Thirdparty UWP package, using default updates check period");
+    }
+    else
     {
     {
-      OnUpdatesChecked = UpdatesChecked;
+      Period = Updates.Period;
+    }
+    AppLogFmt(L"Updates check period: %.2f", (double(Period)));
+    if (double(Period) > 0)
+    {
+      TDateTime Interval = Now() - Updates.LastCheck;
+      AppLogFmt(L"Interval since the last updates check: %.2f", (double(Interval)));
+      if (Interval >= Period)
+      {
+        StartUpdateThread(UpdatesChecked);
+      }
     }
     }
-    StartUpdateThread(OnUpdatesChecked);
   }
   }
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::UpdatesChecked()
 void __fastcall TCustomScpExplorerForm::UpdatesChecked()
 {
 {
+  AppLog(L"Updates check done");
   UnicodeString Message;
   UnicodeString Message;
   bool New;
   bool New;
   TQueryType Type;
   TQueryType Type;
   GetUpdatesMessage(Message, New, Type, false);
   GetUpdatesMessage(Message, New, Type, false);
   if (!Message.IsEmpty())
   if (!Message.IsEmpty())
   {
   {
+    AppLogFmt(L"Updates check message: %s", (Message));
     if (New)
     if (New)
     {
     {
+      AppLog(L"New version detected");
       Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
       Message = FMTLOAD(NEW_VERSION_CLICK, (Message));
     }
     }
     if (!New && (Type != qtWarning))
     if (!New && (Type != qtWarning))
     {
     {
+      AppLog(L"Posting non-critical updates note");
       PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
       PostNote(UnformatMessage(Message), 0, UpdatesNoteClicked, NULL);
     }
     }
     else
     else
     {
     {
+      AppLog(L"Posting new version or critical message notification");
       Notify(NULL, Message, Type, true, UpdatesNoteClicked);
       Notify(NULL, Message, Type, true, UpdatesNoteClicked);
     }
     }
 
 

+ 1 - 1
source/forms/Preferences.cpp

@@ -939,7 +939,7 @@ void __fastcall TPreferencesDialog::SaveConfiguration()
       {
       {
         if (Updates.Period == TDateTime(0))
         if (Updates.Period == TDateTime(0))
         {
         {
-          Updates.Period = 7;
+          Updates.Period = DefaultUpdatesPeriod;
         }
         }
       }
       }
       else
       else

+ 32 - 15
source/windows/Setup.cpp

@@ -901,14 +901,23 @@ static bool __fastcall DoQueryUpdates(TUpdatesConfiguration & Updates, bool Coll
       URL += L"&localever=" + LocaleVersion;
       URL += L"&localever=" + LocaleVersion;
       URL += L"&localecompl=" + LoadStr(TRANSLATION_COMPLETENESS);
       URL += L"&localecompl=" + LoadStr(TRANSLATION_COMPLETENESS);
     }
     }
-    // Even if donor email is inherited from normal installation,
-    // do not use it as this all is merely to report usage statistics, not to check for updates, in UWP.
-    if (!Updates.AuthenticationEmail.IsEmpty() && !IsUWP())
+    URL += L"&firstrun=" + EncodeUrlString(WinConfiguration->FirstRun);
+    if (!IsUWP())
     {
     {
-      RawByteString AuthenticationEmailBuf = RawByteString(UTF8String(Updates.AuthenticationEmail.LowerCase()));
-      URL += L"&authentication=" + Sha256(AuthenticationEmailBuf.c_str(), AuthenticationEmailBuf.Length()).LowerCase();
+      // Even if donor email is inherited from normal installation,
+      // do not use it as this all is merely to report usage statistics, not to check for updates, in UWP.
+      if (!Updates.AuthenticationEmail.IsEmpty())
+      {
+        RawByteString AuthenticationEmailBuf = RawByteString(UTF8String(Updates.AuthenticationEmail.LowerCase()));
+        URL += L"&authentication=" + Sha256(AuthenticationEmailBuf.c_str(), AuthenticationEmailBuf.Length()).LowerCase();
+      }
+    }
+    else
+    {
+      URL += L"&package=" + EncodeUrlString(GetPackageName());
     }
     }
 
 
+    AppLogFmt(L"Updates check URL: %s", (URL));
     CheckForUpdatesHTTP->URL = URL;
     CheckForUpdatesHTTP->URL = URL;
     // sanity check
     // sanity check
     CheckForUpdatesHTTP->ResponseLimit = 102400;
     CheckForUpdatesHTTP->ResponseLimit = 102400;
@@ -934,6 +943,7 @@ static bool __fastcall DoQueryUpdates(TUpdatesConfiguration & Updates, bool Coll
       throw;
       throw;
     }
     }
     Response = CheckForUpdatesHTTP->Response;
     Response = CheckForUpdatesHTTP->Response;
+    AppLogFmt(L"Updates check response: %s", (Response));
   }
   }
   __finally
   __finally
   {
   {
@@ -1148,19 +1158,26 @@ void __fastcall GetUpdatesMessage(UnicodeString & Message, bool & New,
     }
     }
     else
     else
     {
     {
-      New = (Updates.Results.Version > 0);
-      if (New)
+      if (IsUWP())
       {
       {
-        UnicodeString Version = VersionStrFromCompoundVersion(Updates.Results.Version);
-        if (!Updates.Results.Release.IsEmpty())
-        {
-          Version = FORMAT(L"%s %s", (Version, Updates.Results.Release));
-        }
-        Message = FMTLOAD(NEW_VERSION4, (Version));
+        New = false;
       }
       }
       else
       else
       {
       {
-        Message = LoadStr(NO_NEW_VERSION);
+        New = (Updates.Results.Version > 0);
+        if (New)
+        {
+          UnicodeString Version = VersionStrFromCompoundVersion(Updates.Results.Version);
+          if (!Updates.Results.Release.IsEmpty())
+          {
+            Version = FORMAT(L"%s %s", (Version, Updates.Results.Release));
+          }
+          Message = FMTLOAD(NEW_VERSION4, (Version));
+        }
+        else
+        {
+          Message = LoadStr(NO_NEW_VERSION);
+        }
       }
       }
     }
     }
 
 
@@ -1175,7 +1192,7 @@ void __fastcall GetUpdatesMessage(UnicodeString & Message, bool & New,
         FMTLOAD(UPDATE_MESSAGE, (FormatUpdatesMessage(Updates.Results.Message, Updates)));
         FMTLOAD(UPDATE_MESSAGE, (FormatUpdatesMessage(Updates.Results.Message, Updates)));
     }
     }
 
 
-    if (!Updates.Results.AuthenticationError.IsEmpty())
+    if (!Updates.Results.AuthenticationError.IsEmpty() && !IsUWP())
     {
     {
       Message +=
       Message +=
         FMTLOAD(UPDATE_MESSAGE, (FormatUpdatesMessage(Updates.Results.AuthenticationError, Updates)));
         FMTLOAD(UPDATE_MESSAGE, (FormatUpdatesMessage(Updates.Results.AuthenticationError, Updates)));

+ 8 - 0
source/windows/WinConfiguration.cpp

@@ -30,6 +30,7 @@ TWinConfiguration * WinConfiguration = NULL;
 static UnicodeString NotepadName(L"notepad.exe");
 static UnicodeString NotepadName(L"notepad.exe");
 static UnicodeString ToolbarsLayoutKey(L"ToolbarsLayout2");
 static UnicodeString ToolbarsLayoutKey(L"ToolbarsLayout2");
 static UnicodeString ToolbarsLayoutOldKey(L"ToolbarsLayout");
 static UnicodeString ToolbarsLayoutOldKey(L"ToolbarsLayout");
+TDateTime DefaultUpdatesPeriod(7);
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 static const wchar_t FileColorDataSeparator = L':';
 static const wchar_t FileColorDataSeparator = L':';
 TFileColorData::TFileColorData() :
 TFileColorData::TFileColorData() :
@@ -625,6 +626,7 @@ void __fastcall TWinConfiguration::Default()
   UseIconUpdateThread = true;
   UseIconUpdateThread = true;
   AllowWindowPrint = false;
   AllowWindowPrint = false;
   StoreTransition = stInit;
   StoreTransition = stInit;
+  FirstRun = StandardDatestamp();
 
 
   FEditor.Font.FontName = DefaultFixedWidthFontName;
   FEditor.Font.FontName = DefaultFixedWidthFontName;
   FEditor.Font.FontSize = DefaultFixedWidthFontSize;
   FEditor.Font.FontSize = DefaultFixedWidthFontSize;
@@ -1078,6 +1080,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
     KEY(Bool,     UseIconUpdateThread); \
     KEY(Bool,     UseIconUpdateThread); \
     KEY(Bool,     AllowWindowPrint); \
     KEY(Bool,     AllowWindowPrint); \
     KEY(Integer,  StoreTransition); \
     KEY(Integer,  StoreTransition); \
+    KEY(String,   FirstRun); \
   ); \
   ); \
   BLOCK(L"Interface\\Editor", CANCREATE, \
   BLOCK(L"Interface\\Editor", CANCREATE, \
     KEYEX(String,   Editor.Font.FontName, L"FontName2"); \
     KEYEX(String,   Editor.Font.FontName, L"FontName2"); \
@@ -2763,6 +2766,11 @@ void TWinConfiguration::SetStoreTransition(TStoreTransition value)
   SET_CONFIG_PROPERTY(StoreTransition);
   SET_CONFIG_PROPERTY(StoreTransition);
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
+void TWinConfiguration::SetFirstRun(const UnicodeString & value)
+{
+  SET_CONFIG_PROPERTY(FirstRun);
+}
+//---------------------------------------------------------------------------
 TStringList * __fastcall TWinConfiguration::LoadJumpList(
 TStringList * __fastcall TWinConfiguration::LoadJumpList(
   THierarchicalStorage * Storage, UnicodeString Name)
   THierarchicalStorage * Storage, UnicodeString Name)
 {
 {

+ 4 - 0
source/windows/WinConfiguration.h

@@ -210,6 +210,7 @@ struct TUpdatesData
 };
 };
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 enum TConnectionType { ctDirect, ctAuto, ctProxy };
 enum TConnectionType { ctDirect, ctAuto, ctProxy };
+extern TDateTime DefaultUpdatesPeriod;
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 struct TUpdatesConfiguration
 struct TUpdatesConfiguration
 {
 {
@@ -472,6 +473,7 @@ private:
   bool FUseIconUpdateThread;
   bool FUseIconUpdateThread;
   bool FAllowWindowPrint;
   bool FAllowWindowPrint;
   TStoreTransition FStoreTransition;
   TStoreTransition FStoreTransition;
+  UnicodeString FFirstRun;
   int FDontDecryptPasswords;
   int FDontDecryptPasswords;
   int FMasterPasswordSession;
   int FMasterPasswordSession;
   bool FMasterPasswordSessionAsked;
   bool FMasterPasswordSessionAsked;
@@ -589,6 +591,7 @@ private:
   void __fastcall SetUseIconUpdateThread(bool value);
   void __fastcall SetUseIconUpdateThread(bool value);
   void __fastcall SetAllowWindowPrint(bool value);
   void __fastcall SetAllowWindowPrint(bool value);
   void SetStoreTransition(TStoreTransition value);
   void SetStoreTransition(TStoreTransition value);
+  void SetFirstRun(const UnicodeString & value);
   int __fastcall GetLocaleCompletenessTreshold();
   int __fastcall GetLocaleCompletenessTreshold();
 
 
   bool __fastcall GetDDExtInstalled();
   bool __fastcall GetDDExtInstalled();
@@ -788,6 +791,7 @@ public:
   __property bool UseIconUpdateThread = { read = FUseIconUpdateThread, write = SetUseIconUpdateThread };
   __property bool UseIconUpdateThread = { read = FUseIconUpdateThread, write = SetUseIconUpdateThread };
   __property bool AllowWindowPrint = { read = FAllowWindowPrint, write = SetAllowWindowPrint };
   __property bool AllowWindowPrint = { read = FAllowWindowPrint, write = SetAllowWindowPrint };
   __property TStoreTransition StoreTransition = { read = FStoreTransition, write = SetStoreTransition };
   __property TStoreTransition StoreTransition = { read = FStoreTransition, write = SetStoreTransition };
+  __property UnicodeString FirstRun = { read = FFirstRun, write = SetFirstRun };
   __property LCID DefaultLocale = { read = FDefaultLocale };
   __property LCID DefaultLocale = { read = FDefaultLocale };
   __property int LocaleCompletenessTreshold = { read = GetLocaleCompletenessTreshold };
   __property int LocaleCompletenessTreshold = { read = GetLocaleCompletenessTreshold };
 };
 };