release.cpp

Go to the documentation of this file.
00001 // $Id: release.cpp 1304 2006-06-12 23:03:14Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // ReleaseInfo class - informs program about release information
00100 
00101 /*
00102 */
00103 
00104 #include "camtypes.h"
00105 //#include "release.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "brandinf.h"
00107 //#include "justin2.h"
00108 //#include "app.h"      // Camelot object - in camtypes.h [AUTOMATICALLY REMOVED]
00109 
00110 // these are packed so that a brander program can easily find & verify them
00111 
00112 // lets declare a Unicode version of the name, which will be much harder to find
00113 
00114 PORTNOTE("other", "Removed branding stuff")
00115 #ifndef EXCLUDE_FROM_XARALX
00116 // put these in a different segment to the others
00117 #pragma data_seg( "CAMELOT", "DATA" )
00118 struct
00119 {
00120     UINT32 Magic;
00121     UINT32 Serial;
00122     wchar_t Name[BRANDED_NAME_MAX];
00123     wchar_t Company[BRANDED_NAME_MAX];
00124 } SecretInfo =
00125 {
00126     BRANDED_MAGIC2,
00127     BRANDED_SERIALNUMBER ^ BRANDED_XOR,
00128     BRANDED_NAME_UNICODE,
00129     BRANDED_COMPANY_UNICODE
00130 };
00131 
00132 #endif
00133 
00134 #ifndef BRANDED_NAME_MAX
00135     #define BRANDED_NAME_MAX 255
00136 #endif
00137 
00138 #pragma data_seg()
00139 struct p
00140 {
00141     UINT32  Magic;
00142     UINT32  Serial;
00143     TCHAR   Name[BRANDED_NAME_MAX];
00144     TCHAR   Company[BRANDED_NAME_MAX];
00145 } PublicInfo =
00146 #ifndef EXCLUDE_FROM_XARALX
00147 {
00148     BRANDED_MAGIC1,
00149     BRANDED_SERIALNUMBER,
00150     BRANDED_NAME,
00151     BRANDED_COMPANY
00152 };
00153 #else
00154 {
00155     0,
00156     0,
00157     _T("Unregistered user"),
00158     _T("Unregistered company")
00159 };
00160 #endif
00161 
00162 // bug - before 28/2/97 only allocated 10 chars so when it puts 101- and then the
00163 // number to 9 places it will overflow into the next string. This string dictates
00164 // the key name it is written under. So it will be written/read from the wrong section.
00165 static TCHAR szCachedSerial[25] = _T("");
00166 
00167 // Pseudo-Preferences
00168 static TCHAR szUISection[]      = _T("UserInfo");
00169 
00170 static TCHAR szSerialNumber[]   = _T("SerialNo");
00171 static TCHAR szLicensee[]       = _T("Licensee");
00172 static TCHAR szCompany[]        = _T("Company");
00173 
00174 //***************************************************************************
00175 // this returns the obvious user name. Not hidden at all
00176 
00177 
00178 // Why was this class written to use type TCHAR, not TCHAR?   This is a royal pain in the backside.
00179 
00180 const TCHAR *ReleaseInfo::GetInfo()
00181 {
00182     static TCHAR buf[256];
00183 
00184 #ifndef STANDALONE
00185 //  camSprintf(buf, "%s (#101-%09ld)", PublicInfo.Name, PublicInfo.Serial );
00186 //  camSprintf(buf, TEXT("%s (#%s)"), ReleaseInfo::GetLicensee(), ReleaseInfo::GetSerialNumber());
00187 
00188     String_256 jcf;
00189     jcf.MakeMsg(_R(IDS_RELEASE_INFO_FORMAT), ReleaseInfo::GetLicensee(), ReleaseInfo::GetSerialNumber());
00190     camStrcpy(buf, jcf);
00191 
00192 #else
00193     camStrcpy(buf, PublicInfo.Name);
00194 #endif
00195 
00196     return buf;
00197 }
00198 
00199 //***************************************************************************
00200 
00201 const TCHAR* ReleaseInfo::GetLicensee()
00202 {
00203     static TCHAR buffer[64];
00204 #if !defined(EXCLUDE_FROM_XARALX) && defined(_DEBUG)
00205     TCHAR* pLogName=_tgetenv(TCHAR);
00206     if (pLogName!=NULL)
00207         camSprintf(buffer,_T("%s"),pLogName);
00208     else
00209         camSprintf(buffer,_T("%s"),("NoLogName"));
00210 #else
00211     // read the licensee preference value into a string
00212     String_256 Str;
00213     BOOL ok = Camelot.GetPrefDirect(szUISection, szLicensee, &Str);
00214     if (ok) 
00215     {
00216         // copy the string into the return buffer
00217         TCHAR* StringBuf = (TCHAR*)Str;
00218         camSprintf(buffer, _T("%s"), StringBuf);
00219     }
00220     else
00221     {
00222         // something went wrong so use a default, the bound in one
00223         camSprintf(buffer,_T("%s"),PublicInfo.Name);
00224     }
00225 #endif
00226 
00227     return buffer;
00228 }
00229 
00230 //***************************************************************************
00231 
00232 const TCHAR* ReleaseInfo::GetSerialNumber()
00233 {
00234     static TCHAR buffer[64];
00235 
00236     // read the serial number preference value into a string
00237     String_256 Str;
00238     BOOL ok = Camelot.GetPrefDirect(szUISection, szSerialNumber, &Str);
00239     if (ok) 
00240     {
00241         // copy the string into the return buffer
00242         TCHAR* StringBuf = (TCHAR*)Str;
00243         camSprintf(buffer, _T("%s"), StringBuf);
00244     }
00245     else
00246     {
00247         // something went wrong so use a default, the bound in one
00248         camSprintf(buffer,_T("101-%09ld"),PublicInfo.Serial);
00249     }
00250 
00251     return buffer;
00252 }
00253 
00254 //***************************************************************************
00255 
00256 const TCHAR* ReleaseInfo::GetCompany()
00257 {
00258     static TCHAR buffer[64];
00259     // read the company preference value into a string
00260     String_256 Str;
00261     BOOL ok = Camelot.GetPrefDirect(szUISection, szCompany, &Str);
00262     if (ok) 
00263     {
00264         // coy the string into the return buffer
00265         TCHAR* StringBuf = (TCHAR*)Str;
00266         camSprintf(buffer, _T("%s"), StringBuf);
00267     }
00268     else
00269     {
00270         // something went wrong so use a default, the bound in one
00271         camSprintf(buffer,_T("%s"),PublicInfo.Company);
00272     }
00273 
00274     return buffer;
00275 }
00276 
00277 
00278 
00279 /***********************************************************************************************
00280 
00281 >   void ReleaseInfo::CacheProfileSettings()
00282 
00283     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00284     Created:    10/09/96
00285     Purpose:    Stores the current ReleaseInfo settings from the .ini file to an internal buffer
00286                 This is currently used to prevent user information being lost when the default
00287                 user profile is restored.
00288     Scope:      static
00289 
00290     See Also:   RestoreProfileSettings()
00291                                                                  
00292 ***********************************************************************************************/
00293 void ReleaseInfo::CacheProfileSettings()
00294 {
00295     camStrcpy(PublicInfo.Name, GetLicensee());
00296 #ifndef WEBSTER
00297     // No serial number in Webster v2.0.
00298     // This happens too early to get resources.
00299     camStrcpy(szCachedSerial, GetSerialNumber());
00300 #endif
00301     camStrcpy(PublicInfo.Company, GetCompany());
00302 }
00303 
00304 /***********************************************************************************************
00305 
00306 >   BOOL ReleaseInfo::RestoreProfileSettings()
00307 
00308     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00309     Created:    10/09/96
00310     Returns:    TRUE if successful
00311                 FALSE otherwise
00312     Purpose:    Restores the current ReleaseInfo settings in the .ini file to the values
00313                 present in the cache
00314                 This is currently used to prevent user information being lost when the default
00315                 user profile is restored.
00316     Scope:      static
00317 
00318     See Also:   CacheProfileSettings()
00319                                                                  
00320 ***********************************************************************************************/
00321 BOOL ReleaseInfo::RestoreProfileSettings()
00322 {
00323     if (!WriteProfile(szSerialNumber, szCachedSerial))
00324     {
00325         return FALSE;
00326     }
00327 
00328     if (!WriteProfile(szLicensee, PublicInfo.Name))
00329     {
00330         return FALSE;
00331     }
00332 
00333     if (!WriteProfile(szCompany, PublicInfo.Company))
00334     {
00335         return FALSE;
00336     }
00337 
00338     return TRUE;
00339 }
00340 
00341 
00342 /***********************************************************************************************
00343 
00344 >   BOOL ReleaseInfo::WriteProfile(LPCTSTR pKey, LPCTSTR pValue)
00345 
00346     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00347     Created:    10/09/96
00348     Inputs:     pKey:   The key in the .ini file
00349                 pValue: The value to which to set it
00350     Returns:    TRUE if successful
00351                 FALSE otherwise
00352     Scope:      static protected
00353 
00354     Purpose:    Support function for RestoreCurrentSettings()
00355                 Writes an .ini file setting in the UserInfo section of the current apps profile
00356                 file using ::WritePrivateProfileString() and the given key and value.
00357                                                                  
00358 ***********************************************************************************************/
00359 BOOL ReleaseInfo::WriteProfile(LPCTSTR pKey, LPCTSTR pValue)
00360 {
00361     ERROR2IF(pKey == NULL || pValue == NULL,FALSE,"ReleaseInfo::WriteProfile Bad params!");
00362 
00363     // This will be done when the ini file is being vaped. Hence it will happen very soon after
00364     // start up. If this happens to be the first time Camelot is started up then we may be reading
00365     // from ini files and wanting to write the data into the registry. If we do this now then we 
00366     // will be writing into the ini file as we only switch over to the registry when we are
00367     // destructing Camelot. So we must make sure that this info is written out into the registry.
00368     // If we do it now then the registry section may be vaped before we write the real data out.
00369     // We will then need to ensure that if we switch from ini file to registry mode that the data
00370     // is saved out before and restored into the new place afterwards.
00371 
00372     String_256 Key(pKey);
00373     String_256 Section(szUISection);
00374     // don't use this as for some reason it seems to be corrupt
00375     // and says Tips when it comes to calling this
00376     if (!Camelot.SetPrefDirect(Section, Key, pValue, TRUE))
00377         return FALSE;
00378 
00379     return TRUE;
00380 }

Generated on Sat Nov 10 03:46:43 2007 for Camelot by  doxygen 1.4.4