You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(270) |
Sep
(643) |
Oct
(364) |
Nov
(479) |
Dec
(410) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(668) |
Feb
(825) |
Mar
(712) |
Apr
(673) |
May
(525) |
Jun
(523) |
Jul
(875) |
Aug
(600) |
Sep
(1332) |
Oct
(648) |
Nov
(738) |
Dec
(824) |
| 2004 |
Jan
(643) |
Feb
(842) |
Mar
(547) |
Apr
(493) |
May
(746) |
Jun
(917) |
Jul
(296) |
Aug
(446) |
Sep
(546) |
Oct
(325) |
Nov
(329) |
Dec
(326) |
| 2005 |
Jan
(709) |
Feb
(764) |
Mar
(735) |
Apr
(587) |
May
(701) |
Jun
(501) |
Jul
(758) |
Aug
(440) |
Sep
(596) |
Oct
(796) |
Nov
(297) |
Dec
(722) |
| 2006 |
Jan
(1037) |
Feb
(592) |
Mar
(482) |
Apr
(189) |
May
(162) |
Jun
(380) |
Jul
(461) |
Aug
(621) |
Sep
(999) |
Oct
(635) |
Nov
(488) |
Dec
(429) |
| 2007 |
Jan
(453) |
Feb
(568) |
Mar
(379) |
Apr
(424) |
May
(402) |
Jun
(110) |
Jul
(88) |
Aug
(215) |
Sep
(56) |
Oct
(45) |
Nov
(43) |
Dec
(22) |
| 2008 |
Jan
(53) |
Feb
(77) |
Mar
(141) |
Apr
(84) |
May
(141) |
Jun
(40) |
Jul
(107) |
Aug
(71) |
Sep
(30) |
Oct
(37) |
Nov
(47) |
Dec
(50) |
| 2009 |
Jan
(21) |
Feb
(6) |
Mar
(48) |
Apr
(130) |
May
(59) |
Jun
(15) |
Jul
(10) |
Aug
(43) |
Sep
(20) |
Oct
(12) |
Nov
(30) |
Dec
(13) |
| 2010 |
Jan
(9) |
Feb
(56) |
Mar
(24) |
Apr
(9) |
May
(7) |
Jun
(10) |
Jul
(40) |
Aug
(113) |
Sep
(4) |
Oct
|
Nov
(3) |
Dec
(72) |
| 2011 |
Jan
(5) |
Feb
(3) |
Mar
(10) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Chris D. <de...@st...> - 2011-04-02 19:52:27
|
Modified:
branches/4.0/stepmania/src/ProductInfo.h
branches/4.0/stepmania/src/ProductInfo.inc
Log:
version 4.0.0
Modified: branches/4.0/stepmania/src/ProductInfo.h
==============================================================================
--- branches/4.0/stepmania/src/ProductInfo.h (original)
+++ branches/4.0/stepmania/src/ProductInfo.h Sat Apr 2 12:52:20 2011
@@ -9,7 +9,7 @@
#define PRODUCT_FAMILY_BARE StepMania
#define PRODUCT_ID_BARE StepMania4
// String used for the install directory and registry locations
-#define PRODUCT_VER_BARE 4.0.b10
+#define PRODUCT_VER_BARE 4.0.0
// These cannot be #undef'd so make them unlikely to conflict with anything
#define PRODUCT_STRINGIFY(x) #x
Modified: branches/4.0/stepmania/src/ProductInfo.inc
==============================================================================
--- branches/4.0/stepmania/src/ProductInfo.inc (original)
+++ branches/4.0/stepmania/src/ProductInfo.inc Sat Apr 2 12:52:20 2011
@@ -4,7 +4,7 @@
!define PRODUCT_FAMILY "StepMania"
; ID is used for the install directory and registry locations
!define PRODUCT_ID "StepMania4"
-!define PRODUCT_VER "4.0.b10"
+!define PRODUCT_VER "4.0.0"
!define PRODUCT_DISPLAY "${PRODUCT_FAMILY} ${PRODUCT_VER}"
!define PRODUCT_BITMAP "sm4"
|
|
From: Shakesoda <de...@st...> - 2011-03-08 19:30:00
|
Modified:
branches/4.0/stepmania/src/ScreenInstallOverlay.cpp
Log:
Silence non-virtual dtor warning.
Modified: branches/4.0/stepmania/src/ScreenInstallOverlay.cpp
==============================================================================
--- branches/4.0/stepmania/src/ScreenInstallOverlay.cpp (original)
+++ branches/4.0/stepmania/src/ScreenInstallOverlay.cpp Tue Mar 8 11:29:52 2011
@@ -155,7 +155,7 @@ public:
{
m_pTransfer = NULL;
}
- ~DownloadTask()
+ virtual ~DownloadTask()
{
SAFE_DELETE(m_pTransfer);
}
|
|
From: Chris D. <de...@st...> - 2011-03-05 19:46:59
|
Modified: branches/4.0/stepmania/src/ScreenInstallOverlay.cpp Log: allow stepmania protocol downloads from www.stepmania.com and www.stepmaniashare.com Modified: branches/4.0/stepmania/src/ScreenInstallOverlay.cpp ============================================================================== --- branches/4.0/stepmania/src/ScreenInstallOverlay.cpp (original) +++ branches/4.0/stepmania/src/ScreenInstallOverlay.cpp Sat Mar 5 11:46:53 2011 @@ -328,7 +328,9 @@ static bool HandleStepManiaProtocolLaunc static bool IsStepManiaProtocolFile(const RString &arg) { // for now, only load from the StepMania domain until the security implications of this feature are better understood. - return BeginsWith(arg,"stepmania://beta.stepmania.com/"); + static Regex re1( "^stepmania://\\w+.stepmania.com" ); + static Regex re2( "^stepmania://\\w+.stepmaniashare.com" ); // for testing + return re1.Compare(arg) || re2.Compare(arg); } static bool IsSmzip(const RString &arg) |
|
From: Chris D. <de...@st...> - 2011-03-05 19:25:40
|
Modified: branches/4.0/stepmania/src/ScreenEdit.cpp Log: fix save and export commands not working Modified: branches/4.0/stepmania/src/ScreenEdit.cpp ============================================================================== --- branches/4.0/stepmania/src/ScreenEdit.cpp (original) +++ branches/4.0/stepmania/src/ScreenEdit.cpp Sat Mar 5 11:25:33 2011 @@ -2769,6 +2769,8 @@ void ScreenEdit::HandleMainMenuChoice( M case save: case save_on_exit: case export_song: + SaveExport(c); + break; case revert_to_last_save: ScreenPrompt::Prompt( SM_DoRevertToLastSave, REVERT_LAST_SAVE.GetValue() + "\n\n" + DESTROY_ALL_UNSAVED_CHANGES.GetValue(), PROMPT_YES_NO, ANSWER_NO ); break; |
|
From: Chris D. <de...@st...> - 2011-03-05 19:25:05
|
Modified:
branches/4.0/stepmania/src/ExportPackage.cpp
Log:
remove leading underscore from exported package name
Modified: branches/4.0/stepmania/src/ExportPackage.cpp
==============================================================================
--- branches/4.0/stepmania/src/ExportPackage.cpp (original)
+++ branches/4.0/stepmania/src/ExportPackage.cpp Sat Mar 5 11:24:58 2011
@@ -49,8 +49,6 @@ void StripIgnoredSmzipFiles( vector<RStr
bool ExportDir( RString sSmzipFile, RString sDirToExport, RString &sErrorOut )
{
- //sSmzipFile = "/simple1.zip";
-
RageFile f;
// TODO: Mount Desktop/ for each OS
if( !f.Open(sSmzipFile, RageFile::WRITE) )
@@ -86,7 +84,10 @@ bool ExportDir( RString sSmzipFile, RStr
RString ExportSong( const Song *pSong )
{
RString sDirToExport = pSong->GetSongDir();
- RString sPackageName = ReplaceInvalidFileNameChars( sDirToExport + ".smzip" );
+
+ RString sPackageName = sDirToExport;
+ TrimLeft( sPackageName, "/" );
+ sPackageName = ReplaceInvalidFileNameChars( sPackageName + ".smzip" );
RString sSmzipFile = SpecialFiles::DESKTOP_DIR + sPackageName;
|
|
From: Chris D. <de...@st...> - 2011-03-05 19:24:32
|
Modified:
branches/4.0/stepmania/src/ScreenInstallOverlay.cpp
Log:
Don't show username system message until username is changing
Modified: branches/4.0/stepmania/src/ScreenInstallOverlay.cpp
==============================================================================
--- branches/4.0/stepmania/src/ScreenInstallOverlay.cpp (original)
+++ branches/4.0/stepmania/src/ScreenInstallOverlay.cpp Sat Mar 5 11:24:24 2011
@@ -275,8 +275,12 @@ void HandleLaunch( RString sJson )
// Parse the JSON response, make a list of all packages need to be downloaded.
if( root["Username"].isString() )
{
- g_sUsername.Set( root["Username"].asString() );
- SCREENMAN->SystemMessage("Logged in as " + g_sUsername.Get() );
+ RString sNewUsername = root["Username"].asString();
+ if( g_sUsername.Get() != sNewUsername )
+ {
+ g_sUsername.Set( sNewUsername );
+ SCREENMAN->SystemMessage("Logged in as " + sNewUsername );
+ }
}
if( root["Cookie"].isString() )
g_sCookie.Set( root["Cookie"].asString() );
|
|
From: Chris D. <de...@st...> - 2011-03-05 18:29:44
|
Modified:
branches/4.0/stepmania/src/ExportPackage.cpp
branches/4.0/stepmania/src/ScreenEdit.cpp
branches/4.0/stepmania/src/ScreenEdit.h
Log:
rip out in-game song upload. This is better done in the browser.
Modified: branches/4.0/stepmania/src/ExportPackage.cpp
==============================================================================
--- branches/4.0/stepmania/src/ExportPackage.cpp (original)
+++ branches/4.0/stepmania/src/ExportPackage.cpp Sat Mar 5 10:29:37 2011
@@ -83,56 +83,6 @@ bool ExportDir( RString sSmzipFile, RStr
return true;
}
-RString PublishSong( const Song *pSong )
-{
- {
- FileTransfer fd;
- fd.StartDownload( "http://www.stepmania.com/api.php?action=is_logged_in", "");
- fd.BlockUntilFinished();
- if( fd.GetResponseCode() != 200 )
- return "Bad response code is_logged_in " + fd.GetResponseCode();
- XNode xml;
- PARSEINFO pi;
- xml.Load( fd.GetResponse(), &pi );
- if( pi.error_occur )
- return "Error parsing is_logged_in " + pi.error_string;
- if( xml.m_sName != "is_logged_in" )
- return "Unexpected response in is_logged_in";
- bool bIsLoggedIn = xml.m_sValue == "1";
- if( !bIsLoggedIn )
- {
- HOOKS->GoToURL("http://www.stepmania.com/launch.php");
- return "You must log into StepMania.com. Launching.";
- }
- }
-
- RString sDirToExport = pSong->GetSongDir();
- RString sPackageName = ReplaceInvalidFileNameChars( sDirToExport + ".smzip" );
-
- RString sSmzipFile = SpecialFiles::CACHE_DIR + "Uploads/" + sPackageName;
-
- RString sErrorOut;
- if( !ExportDir(sSmzipFile, sDirToExport, sErrorOut) )
- return "Failed to export '" + sDirToExport + "' to '" + sSmzipFile + "'";
-
- RString sUrl = "unknown url";
- {
- FileTransfer ft;
- ft.StartUpload( "http://www.stepmania.com/api.php?action=upload_song", sSmzipFile, "" );
- ft.BlockUntilFinished();
- if( ft.GetResponseCode() != 200 )
- return "Bad response code upload_song " + ft.GetResponseCode();
- RString sResponse = ft.GetResponse();
- Json::Value root;
- RString sError;
- if( !JsonUtil::LoadFromString(root,sResponse,sError) )
- return "Error parsing response: " + sError;
- HOOKS->GoToURL(root["url"].asString());
- }
-
- return "Published as '" + sUrl + "'";
-}
-
RString ExportSong( const Song *pSong )
{
RString sDirToExport = pSong->GetSongDir();
@@ -147,11 +97,6 @@ RString ExportSong( const Song *pSong )
return "Exported as '" + sSmzipFile + "'";
}
-void ExportPackage::PublishSongWithUI( const Song *pSong )
-{
- RString sResult = PublishSong( pSong );
- ScreenPrompt::Prompt( SM_None, sResult );
-}
void ExportPackage::ExportSongWithUI( const Song *pSong )
{
RString sResult = ExportSong( pSong );
Modified: branches/4.0/stepmania/src/ScreenEdit.cpp
==============================================================================
--- branches/4.0/stepmania/src/ScreenEdit.cpp (original)
+++ branches/4.0/stepmania/src/ScreenEdit.cpp Sat Mar 5 10:29:37 2011
@@ -477,7 +477,6 @@ static MenuDef g_MainMenu(
MenuRowDef( ScreenEdit::play_whole_song, "Play whole song", true, EditMode_Practice, true, true, 0, NULL ),
MenuRowDef( ScreenEdit::play_current_beat_to_end, "Play current beat to end", true, EditMode_Practice, true, true, 0, NULL ),
MenuRowDef( ScreenEdit::save, "Save", true, EditMode_Home, true, true, 0, NULL ),
- MenuRowDef( ScreenEdit::publish, "Publish to StepMania.com", true, EditMode_Home, true, true, 0, NULL ),
MenuRowDef( ScreenEdit::export_song, "Export .smzip to Desktop", true, EditMode_Home, true, true, 0, NULL ),
MenuRowDef( ScreenEdit::revert_to_last_save, "Revert to last save", true, EditMode_Home, true, true, 0, NULL ),
MenuRowDef( ScreenEdit::revert_from_disk, "Revert from disk", true, EditMode_Full, true, true, 0, NULL ),
@@ -2770,9 +2769,6 @@ void ScreenEdit::HandleMainMenuChoice( M
case save:
case save_on_exit:
case export_song:
- case publish:
- SaveExportPublish(c);
- break;
case revert_to_last_save:
ScreenPrompt::Prompt( SM_DoRevertToLastSave, REVERT_LAST_SAVE.GetValue() + "\n\n" + DESTROY_ALL_UNSAVED_CHANGES.GetValue(), PROMPT_YES_NO, ANSWER_NO );
break;
@@ -2835,7 +2831,7 @@ void ScreenEdit::HandleMainMenuChoice( M
};
}
-void ScreenEdit::SaveExportPublish(MainMenuChoice c)
+void ScreenEdit::SaveExport(MainMenuChoice c)
{
m_CurrentAction = c;
@@ -2903,9 +2899,6 @@ void ScreenEdit::SaveExportPublish(MainM
case save_on_exit:
HandleScreenMessage( SM_SaveSuccessful );
break;
- case publish:
- ExportPackage::PublishSongWithUI(pSong);
- break;
case export_song:
ExportPackage::ExportSongWithUI(pSong);
break;
Modified: branches/4.0/stepmania/src/ScreenEdit.h
==============================================================================
--- branches/4.0/stepmania/src/ScreenEdit.h (original)
+++ branches/4.0/stepmania/src/ScreenEdit.h Sat Mar 5 10:29:37 2011
@@ -284,7 +284,6 @@ public:
play_selection_start_to_end,
play_current_beat_to_end,
save,
- publish,
export_song,
revert_to_last_save,
revert_from_disk,
@@ -300,7 +299,7 @@ public:
};
void HandleMainMenuChoice( MainMenuChoice c, const vector<int> &iAnswers );
void HandleMainMenuChoice( MainMenuChoice c ) { const vector<int> v; HandleMainMenuChoice( c, v ); }
- void SaveExportPublish(MainMenuChoice c);
+ void SaveExport(MainMenuChoice c);
MainMenuChoice m_CurrentAction;
enum AreaMenuChoice
|
|
From: Chris D. <de...@st...> - 2011-03-05 18:28:05
|
Modified:
branches/4.0/stepmania/src/GameState.cpp
Log:
comment out call to UploadMachineProfile for a stable release
Modified: branches/4.0/stepmania/src/GameState.cpp
==============================================================================
--- branches/4.0/stepmania/src/GameState.cpp (original)
+++ branches/4.0/stepmania/src/GameState.cpp Sat Mar 5 10:27:59 2011
@@ -386,7 +386,7 @@ void GameState::PlayersFinalized()
void SaveAllProfiles( bool bEndGame )
{
PROFILEMAN->SaveMachineProfile();
- PROFILEMAN->UploadMachineProfie();
+ //PROFILEMAN->UploadMachineProfie();
FOREACH_HumanPlayer( pn )
{
if( !PROFILEMAN->IsPersistentProfile(pn) )
|
|
From: Chris D. <de...@st...> - 2011-03-05 18:26:44
|
Modified:
branches/4.0/stepmania/src/ProductInfo.h
branches/4.0/stepmania/src/ProductInfo.inc
Log:
version bump to 4.0b10
Modified: branches/4.0/stepmania/src/ProductInfo.h
==============================================================================
--- branches/4.0/stepmania/src/ProductInfo.h (original)
+++ branches/4.0/stepmania/src/ProductInfo.h Sat Mar 5 10:26:37 2011
@@ -9,7 +9,7 @@
#define PRODUCT_FAMILY_BARE StepMania
#define PRODUCT_ID_BARE StepMania4
// String used for the install directory and registry locations
-#define PRODUCT_VER_BARE 4.0.b9
+#define PRODUCT_VER_BARE 4.0.b10
// These cannot be #undef'd so make them unlikely to conflict with anything
#define PRODUCT_STRINGIFY(x) #x
Modified: branches/4.0/stepmania/src/ProductInfo.inc
==============================================================================
--- branches/4.0/stepmania/src/ProductInfo.inc (original)
+++ branches/4.0/stepmania/src/ProductInfo.inc Sat Mar 5 10:26:37 2011
@@ -4,7 +4,7 @@
!define PRODUCT_FAMILY "StepMania"
; ID is used for the install directory and registry locations
!define PRODUCT_ID "StepMania4"
-!define PRODUCT_VER "4.0.b9"
+!define PRODUCT_VER "4.0.b10"
!define PRODUCT_DISPLAY "${PRODUCT_FAMILY} ${PRODUCT_VER}"
!define PRODUCT_BITMAP "sm4"
|
|
From: Chris D. <de...@st...> - 2011-03-05 18:26:04
|
Modified:
branches/4.0/stepmania/src/ScreenInstallOverlay.cpp
Log:
fix launching twice for each login key press
Modified: branches/4.0/stepmania/src/ScreenInstallOverlay.cpp
==============================================================================
--- branches/4.0/stepmania/src/ScreenInstallOverlay.cpp (original)
+++ branches/4.0/stepmania/src/ScreenInstallOverlay.cpp Sat Mar 5 10:25:57 2011
@@ -371,7 +371,7 @@ void ScreenInstallOverlay::Init()
bool ScreenInstallOverlay::OverlayInput( const InputEventPlus &input )
{
- if( input.DeviceI.button == g_buttonLogin )
+ if( input.DeviceI.button == g_buttonLogin && input.type == IET_FIRST_PRESS )
{
HOOKS->GoToURL("http://www.stepmania.com/launch.php");
return true;
|
|
From: Chris D. <de...@st...> - 2011-03-05 18:25:27
|
Modified:
branches/4.0/stepmania/OCSetupHlp.dll
branches/4.0/stepmania/OCSetupHlp.nsh
branches/4.0/stepmania/stepmania.nsi
Log:
Upgrade OC SDK from 1.4 to 1.6
Modified: branches/4.0/stepmania/OCSetupHlp.dll
==============================================================================
Binary files. No diff available.
Modified: branches/4.0/stepmania/OCSetupHlp.nsh
==============================================================================
--- branches/4.0/stepmania/OCSetupHlp.nsh (original)
+++ branches/4.0/stepmania/OCSetupHlp.nsh Sat Mar 5 10:25:18 2011
@@ -5,1445 +5,843 @@
; OpenCandy Helper Include File
;
; This file defines a few macros that need to be called
-; from your main installer script in order to initialize and
-; setup OpenCandy.
+; from your main installer script in order to initialize
+; and setup OpenCandy.
;
-; Copyright (c) 2008, 2010 - OpenCandy, Inc.
+; Please consult the accompanying SDK documentation for
+; integration details and contact partner support for
+; assistance with any advanced integration needs.
;
+; IMPORTANT:
+; ----------
+; Publishers should have no need to modify the content
+; of this file. If you are modifying this file for any
+; reason other than as directed by partner support
+; you are probably making a mistake. Please contact
+; partner support instead.
+;
+; Note: When using the Unicode NSIS compiler this file
+; must be re-saved with UTF-16LE/UCS-2LE encoding
+; for versions of Unicode NSIS up to 2.42.3,
+; and either UTF16-LE/UCS2LE or UTF8 encoding
+; for versions thereafter.
+;
+; Copyright (c) 2008 - 2011 OpenCandy, Inc.
+;
+
+!ifdef _OCSETUPHLP_NSH
+!warning "OCSetupHlp.nsh is included more than once"
+!else
+!define _OCSETUPHLP_NSH
+
+
+
+;--------------------------------
+; Include and prepare NSIS libraries used
+;--------------------------------
!include FileFunc.nsh
!include nsDialogs.nsh
!insertmacro GetParameters
-; Local Variables
-Var OCUseOfferPage
-Var OCPageTitle
-Var OCPageDesc
-Var OCDetached
-Var OCDialog
-Var OCPPLabel
-Var OCTOULabel
-Var OCProductKey
+
+;--------------------------------
+; OpenCandy definitions
+;--------------------------------
+
+; Size of strings (including terminating character)
+!define OC_STR_CHARS 1024
+
+; Values used with OCInit2A(), OCInit2W() APIs
+!define OC_INIT_SUCCESS 0
+!define OC_INIT_ASYNC_ENABLE 1
+!define OC_INIT_ASYNC_DISABLE 0
+!define OC_INIT_MODE_NORMAL 0
+!define OC_INIT_MODE_REMNANT 1
+
+; Values used with OCGetNoCandy() API
+!define OC_CANDY_ENABLED 0
+!define OC_CANDY_DISABLED 1
+
+; Offer types returned by OCGetOfferType() API
+!define OC_OFFER_TYPE_NORMAL 1
+!define OC_OFFER_TYPE_EMBEDDED 2
+
+; User choice indicators returned by OCGetOfferState() API
+!define OC_OFFER_CHOICE_ACCEPTED 1
+!define OC_OFFER_CHOICE_DECLINED 0
+!define OC_OFFER_CHOICE_NOCHOICE -1
+
+; Values used with OCCanLeaveOfferPage() API
+!define OC_OFFER_LEAVEPAGE_ALLOWED 1
+!define OC_OFFER_LEAVEPAGE_DISALLOWED 0
+
+; Values used for OCGetAsyncOfferStatus() API
+!define OC_OFFER_STATUS_CANOFFER_READY 0
+!define OC_OFFER_STATUS_CANOFFER_NOTREADY 1
+!define OC_OFFER_STATUS_QUERYING_NOTREADY 2
+!define OC_OFFER_STATUS_NOOFFERSAVAILABLE 3
+!define OC_STATUS_QUERY_GENERAL 0
+!define OC_STATUS_QUERY_DETERMINESOFFERENABLED 1
+
+; Values returned by OCGetBannerInfo() API
+!define OC_OFFER_BANNER_FOUNDNEITHER 0
+!define OC_OFFER_BANNER_FOUNDTITLE 1
+!define OC_OFFER_BANNER_FOUNDDESCRIPTION 2
+!define OC_OFFER_BANNER_FOUNDBOTH 3
+
+; Values returned by OCRunDialog() API
+!define OC_OFFER_RUNDIALOG_FAILURE -1
+
+; Values for LogDevModeMessage() API
+!define OC_DEVMSG_ERROR_TRUE 1
+!define OC_DEVMSG_ERROR_FALSE 0
+
+; Values used for SetOCOfferEnabled() API
+!define OC_OFFER_ENABLE_TRUE 1
+!define OC_OFFER_ENABLE_FALSE 0
+
+; Values returned by OCLoadOpenCandyDLL() API
+!define OC_LOADOCDLL_FAILURE 0
+
+; Flags used in NSIS script
+!define OC_NSIS_TRUE 1
+!define OC_NSIS_FALSE 0
+
+; Values used in the sample installer script
+;
+; IMPORTANT:
+; Do not modify these definitions or disable the warnings below.
+; If you see warnings when you compile your script you must
+; modify the values you set where you !insertmacro OpenCandyInit
+; (i.e. in your .nsi file) before releasing your installer publicly.
+!define OC_SAMPLE_PUBLISHERNAME "Open Candy Sample"
+!define OC_SAMPLE_KEY "748ad6d80864338c9c03b664839d8161"
+!define OC_SAMPLE_SECRET "dfb3a60d6bfdb55c50e1ef53249f1198"
+
+
+
+;--------------------------------
+; OpenCandy global variables
+;--------------------------------
+
+; IMPORTANT:
+; Never modify or reference these directly, they are used
+; completely internally to this helper script.
+Var OCHasBeenInitialized
Var OCNoCandy
-Var OCRemnant
-Var OCOSSupported
-Var OCInitcode
+Var OCUseOfferPage
+Var OCProductInstallSuccess
+Var OCAttached
+Var OCHasReachedOCPage
-;
-; Local Functions
-; -----------------
-;
-; These functions are only used here, and
-; are not part of the exposed OC API
-;
-!ifndef NSIS_UNICODE
+;--------------------------------
+; OpenCandy functions and macros
+;--------------------------------
;
-; ConvertMultiByte (converts between codepages)
-; ----------------
+; OpenCandy API check
+; -------------------
+; Perform a basic sanity check to ensure that your script
+; inserts all mandatory API calls. Any failures will be
+; shown as warnings from the compiler at compile time.
+;
+; To perform this check insert the OpenCandyAPIDoChecks
+; macro at the very bottom of your .nsi file.
;
-; We use this function to convert from
-; UTF-8 (codepage 65001) to the codepage
-; NSIS is using ($LANGUAGE) for server-sent
-; strings that need to be displayed
+; The _OpenCandyAPIInserted and _OpenCandyAPICheckInserted
+; macros are internal to this helper script, do not insert
+; them in your code.
;
; Usage:
-; ------
-; Push "Blah" # Input text
-; Push "65001" # Input text code page (usually CP_UTF8)
-; Push "1036" # Output text code page (Usually $LANGUAGE)
-; Call ConvertMultiByte # Actual Function Call
-; Pop $0 # Retrieve Output text
-;
-
-Function ConvertMultiByte
-
- Exch $2
- Exch
- Exch $1
- Exch
- Exch 2
- Exch $0
- Exch 2
- Push $3
- Push $4
- Push $5
- Push $6
- Push $7
- Push $8
- Push $9
-
- StrLen $3 $0
- IntOp $3 $3 + 1
- IntOp $4 $3 * 2
- IntOp $5 $3 * 3
-
- System::Alloc /NOUNLOAD $4
- Pop $6
- System::Call /NOUNLOAD 'kernel32::MultiByteToWideChar(i $1, i 0, t r0, i r3, i r6, i r3) i .r8'
-
- System::Alloc /NOUNLOAD $5
- Pop $7
- System::Call /NOUNLOAD 'kernel32::WideCharToMultiByte(i $2, i 0, i r6, i r8, i r7, i r5, i 0, i 0) i .r9'
-
- ; Check if we got an error, which may happen if the desired codepage
- ; is not installed in which case we will fallback to ANSI codepage (0)
-
- IntCmp $9 0 ANSI_Needed
- Goto ANSI_Not_Needed
-
-ANSI_Needed:
-
- System::Call /NOUNLOAD 'kernel32::WideCharToMultiByte(i 0, i 0, i r6, i r8, i r7, i r5, i 0, i 0) i .r9'
-
-ANSI_Not_Needed:
-
- System::Call /NOUNLOAD '*$7(&t$5 .r0)'
- System::Free /NOUNLOAD $6
- System::Free $7
-
- Pop $9
- Pop $8
- Pop $7
- Pop $6
- Pop $5
- Pop $4
- Pop $3
- Pop $2
- Pop $1
-
- Exch $0
-
-FunctionEnd
-
-!endif ; NSIS_UNICODE
-
;
-; GetLanguageString
+; # Have the compiler perform some basic OpenCandy API implementation checks
+; # This macro must be inserted at the very end of the .nsi script,
+; # outside any other code blocks.
+; !insertmacro OpenCandyAPIDoChecks
;
-Function GetLanguageString
-
- ${If} $LANGUAGE == 1078
- StrCpy $0 "af" ; Afrikaans
- ${ElseIf} $LANGUAGE == 1052
- StrCpy $0 "sq" ; Albanian
- ${ElseIf} $LANGUAGE == 1118
- StrCpy $0 "am" ; Amharic
- ${ElseIf} $LANGUAGE == 1025
- StrCpy $0 "ar" ; Arabic - Saudi Arabia
- ${ElseIf} $LANGUAGE == 5121
- StrCpy $0 "ar" ; Arabic - Algeria
- ${ElseIf} $LANGUAGE == 15361
- StrCpy $0 "ar" ; Arabic - Bahrain
- ${ElseIf} $LANGUAGE == 3073
- StrCpy $0 "ar" ; Arabic - Egypt
- ${ElseIf} $LANGUAGE == 2049
- StrCpy $0 "ar" ; Arabic - Iraq
- ${ElseIf} $LANGUAGE == 11265
- StrCpy $0 "ar" ; Arabic - Jordan
- ${ElseIf} $LANGUAGE == 13313
- StrCpy $0 "ar" ; Arabic - Kuwait
- ${ElseIf} $LANGUAGE == 12289
- StrCpy $0 "ar" ; Arabic - Lebanon
- ${ElseIf} $LANGUAGE == 4097
- StrCpy $0 "ar" ; Arabic - Libya
- ${ElseIf} $LANGUAGE == 6145
- StrCpy $0 "ar" ; Arabic - Morocco
- ${ElseIf} $LANGUAGE == 8193
- StrCpy $0 "ar" ; Arabic - Oman
- ${ElseIf} $LANGUAGE == 16385
- StrCpy $0 "ar" ; Arabic - Qatar
- ${ElseIf} $LANGUAGE == 10241
- StrCpy $0 "ar" ; Arabic - Syria
- ${ElseIf} $LANGUAGE == 7169
- StrCpy $0 "ar" ; Arabic - Tunisia
- ${ElseIf} $LANGUAGE == 14337
- StrCpy $0 "ar" ; Arabic - U.A.E.
- ${ElseIf} $LANGUAGE == 9217
- StrCpy $0 "ar" ; Arabic - Yemen
- ${ElseIf} $LANGUAGE == 1067
- StrCpy $0 "hy" ; Armenian - Armenia
- ${ElseIf} $LANGUAGE == 1101
- StrCpy $0 "as" ; Assamese
- ${ElseIf} $LANGUAGE == 2092
- StrCpy $0 "az" ; Azeri (Cyrillic)
- ${ElseIf} $LANGUAGE == 1068
- StrCpy $0 "az" ; Azeri (Latin)
- ${ElseIf} $LANGUAGE == 1069
- StrCpy $0 "eu" ; Basque
- ${ElseIf} $LANGUAGE == 1059
- StrCpy $0 "be" ; Belarusian
- ${ElseIf} $LANGUAGE == 1093
- StrCpy $0 "bn" ; Bengali (India)
- ${ElseIf} $LANGUAGE == 2117
- StrCpy $0 "bn" ; Bengali (Bangladesh)
- ${ElseIf} $LANGUAGE == 5146
- StrCpy $0 "bs" ; Bosnian (Bosnia/Herzegovina)
- ${ElseIf} $LANGUAGE == 1026
- StrCpy $0 "bg" ; Bulgarian
- ${ElseIf} $LANGUAGE == 1109
- StrCpy $0 "my" ; Burmese
- ${ElseIf} $LANGUAGE == 1027
- StrCpy $0 "ca" ; Catalan
- ${ElseIf} $LANGUAGE == 1116
- StrCpy $0 "en" ; Cherokee - United States (no twochar lang code)
- ${ElseIf} $LANGUAGE == 2052
- StrCpy $0 "zh" ; Chinese - People's Republic of China
- ${ElseIf} $LANGUAGE == 4100
- StrCpy $0 "zh" ; Chinese - Singapore
- ${ElseIf} $LANGUAGE == 1028
- StrCpy $0 "zh" ; Chinese - Taiwan
- ${ElseIf} $LANGUAGE == 3076
- StrCpy $0 "zh" ; Chinese - Hong Kong SAR
- ${ElseIf} $LANGUAGE == 5124
- StrCpy $0 "zh" ; Chinese - Macao SAR
- ${ElseIf} $LANGUAGE == 1050
- StrCpy $0 "hr" ; Croatian
- ${ElseIf} $LANGUAGE == 4122
- StrCpy $0 "hr" ; Croatian (Bosnia/Herzegovina)
- ${ElseIf} $LANGUAGE == 1029
- StrCpy $0 "cs" ; Czech
- ${ElseIf} $LANGUAGE == 1030
- StrCpy $0 "da" ; Danish
- ${ElseIf} $LANGUAGE == 1125
- StrCpy $0 "dv" ; Divehi
- ${ElseIf} $LANGUAGE == 1043
- StrCpy $0 "nl" ; Dutch - Netherlands
- ${ElseIf} $LANGUAGE == 2067
- StrCpy $0 "nl" ; Dutch - Belgium
- ${ElseIf} $LANGUAGE == 1126
- StrCpy $0 "en" ; Edo (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1033
- StrCpy $0 "en" ; English - United States
- ${ElseIf} $LANGUAGE == 2057
- StrCpy $0 "en" ; English - United Kingdom
- ${ElseIf} $LANGUAGE == 3081
- StrCpy $0 "en" ; English - Australia
- ${ElseIf} $LANGUAGE == 10249
- StrCpy $0 "en" ; English - Belize
- ${ElseIf} $LANGUAGE == 4105
- StrCpy $0 "en" ; English - Canada
- ${ElseIf} $LANGUAGE == 9225
- StrCpy $0 "en" ; English - Caribbean
- ${ElseIf} $LANGUAGE == 15369
- StrCpy $0 "en" ; English - Hong Kong SAR
- ${ElseIf} $LANGUAGE == 16393
- StrCpy $0 "en" ; English - India
- ${ElseIf} $LANGUAGE == 14345
- StrCpy $0 "en" ; English - Indonesia
- ${ElseIf} $LANGUAGE == 6153
- StrCpy $0 "en" ; English - Ireland
- ${ElseIf} $LANGUAGE == 8201
- StrCpy $0 "en" ; English - Jamaica
- ${ElseIf} $LANGUAGE == 17417
- StrCpy $0 "en" ; English - Malaysia
- ${ElseIf} $LANGUAGE == 5129
- StrCpy $0 "en" ; English - New Zealand
- ${ElseIf} $LANGUAGE == 13321
- StrCpy $0 "en" ; English - Philippines
- ${ElseIf} $LANGUAGE == 18441
- StrCpy $0 "en" ; English - Singapore
- ${ElseIf} $LANGUAGE == 7177
- StrCpy $0 "en" ; English - South Africa
- ${ElseIf} $LANGUAGE == 11273
- StrCpy $0 "en" ; English - Trinidad
- ${ElseIf} $LANGUAGE == 12297
- StrCpy $0 "en" ; English - Zimbabwe
- ${ElseIf} $LANGUAGE == 1061
- StrCpy $0 "et" ; Estonian
- ${ElseIf} $LANGUAGE == 1080
- StrCpy $0 "fo" ; Faroese
- ${ElseIf} $LANGUAGE == 1065
- StrCpy $0 "en" ; Farsi (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1124
- StrCpy $0 "en" ; Filipino (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1035
- StrCpy $0 "fi" ; Finnish
- ${ElseIf} $LANGUAGE == 1036
- StrCpy $0 "fr" ; French - France
- ${ElseIf} $LANGUAGE == 2060
- StrCpy $0 "fr" ; French - Belgium
- ${ElseIf} $LANGUAGE == 11276
- StrCpy $0 "fr" ; French - Cameroon
- ${ElseIf} $LANGUAGE == 3084
- StrCpy $0 "fr" ; French - Canada
- ${ElseIf} $LANGUAGE == 9228
- StrCpy $0 "fr" ; French - Democratic Rep. of Congo
- ${ElseIf} $LANGUAGE == 12300
- StrCpy $0 "fr" ; French - Cote d'Ivoire
- ${ElseIf} $LANGUAGE == 15372
- StrCpy $0 "fr" ; French - Haiti
- ${ElseIf} $LANGUAGE == 5132
- StrCpy $0 "fr" ; French - Luxembourg
- ${ElseIf} $LANGUAGE == 13324
- StrCpy $0 "fr" ; French - Mali
- ${ElseIf} $LANGUAGE == 6156
- StrCpy $0 "fr" ; French - Monaco
- ${ElseIf} $LANGUAGE == 14348
- StrCpy $0 "fr" ; French - Morocco
- ${ElseIf} $LANGUAGE == 58380
- StrCpy $0 "fr" ; French - North Africa
- ${ElseIf} $LANGUAGE == 8204
- StrCpy $0 "fr" ; French - Reunion
- ${ElseIf} $LANGUAGE == 10252
- StrCpy $0 "fr" ; French - Senegal
- ${ElseIf} $LANGUAGE == 4108
- StrCpy $0 "fr" ; French - Switzerland
- ${ElseIf} $LANGUAGE == 7180
- StrCpy $0 "fr" ; French - West Indies
- ${ElseIf} $LANGUAGE == 1127
- StrCpy $0 "ff" ; Fulfulde - Nigeria
- ${ElseIf} $LANGUAGE == 1122
- StrCpy $0 "fy" ; Frisian - Netherlands
- ${ElseIf} $LANGUAGE == 1071
- StrCpy $0 "mk" ; FYRO Macedonian
- ${ElseIf} $LANGUAGE == 2108
- StrCpy $0 "gd" ; Gaelic (Ireland)
- ${ElseIf} $LANGUAGE == 1084
- StrCpy $0 "gd" ; Gaelic (Scotland)
- ${ElseIf} $LANGUAGE == 1110
- StrCpy $0 "gl" ; Galician
- ${ElseIf} $LANGUAGE == 1079
- StrCpy $0 "ka" ; Georgian
- ${ElseIf} $LANGUAGE == 1031
- StrCpy $0 "de" ; German - Germany
- ${ElseIf} $LANGUAGE == 3079
- StrCpy $0 "de" ; German - Austria
- ${ElseIf} $LANGUAGE == 5127
- StrCpy $0 "de" ; German - Liechtenstein
- ${ElseIf} $LANGUAGE == 4103
- StrCpy $0 "de" ; German - Luxembourg
- ${ElseIf} $LANGUAGE == 2055
- StrCpy $0 "de" ; German - Switzerland
- ${ElseIf} $LANGUAGE == 1032
- StrCpy $0 "el" ; Greek
- ${ElseIf} $LANGUAGE == 1140
- StrCpy $0 "gn" ; Guarani - Paraguay
- ${ElseIf} $LANGUAGE == 1095
- StrCpy $0 "gu" ; Gujarati
- ${ElseIf} $LANGUAGE == 1128
- StrCpy $0 "ha" ; Hausa - Nigeria
- ${ElseIf} $LANGUAGE == 1141
- StrCpy $0 "en" ; Hawaiian - United States (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1037
- StrCpy $0 "he" ; Hebrew
- ${ElseIf} $LANGUAGE == 1081
- StrCpy $0 "hi" ; Hindi
- ${ElseIf} $LANGUAGE == 1038
- StrCpy $0 "hu" ; Hungarian
- ${ElseIf} $LANGUAGE == 1129
- StrCpy $0 "ig" ; Ibibio - Nigeria
- ${ElseIf} $LANGUAGE == 1039
- StrCpy $0 "is" ; Icelandic
- ${ElseIf} $LANGUAGE == 1136
- StrCpy $0 "ig" ; Igbo - Nigeria
- ${ElseIf} $LANGUAGE == 1057
- StrCpy $0 "id" ; Indonesian
- ${ElseIf} $LANGUAGE == 1117
- StrCpy $0 "iu" ; Inuktitut
- ${ElseIf} $LANGUAGE == 1040
- StrCpy $0 "it" ; Italian - Italy
- ${ElseIf} $LANGUAGE == 2064
- StrCpy $0 "it" ; Italian - Switzerland
- ${ElseIf} $LANGUAGE == 1041
- StrCpy $0 "ja" ; Japanese
- ${ElseIf} $LANGUAGE == 1099
- StrCpy $0 "kn" ; Kannada
- ${ElseIf} $LANGUAGE == 1137
- StrCpy $0 "kr" ; Kanuri - Nigeria
- ${ElseIf} $LANGUAGE == 2144
- StrCpy $0 "ks" ; Kashmiri
- ${ElseIf} $LANGUAGE == 1120
- StrCpy $0 "ks" ; Kashmiri (Arabic)
- ${ElseIf} $LANGUAGE == 1087
- StrCpy $0 "kk" ; Kazakh
- ${ElseIf} $LANGUAGE == 1107
- StrCpy $0 "km" ; Khmer
- ${ElseIf} $LANGUAGE == 1111
- StrCpy $0 "ki" ; Konkani
- ${ElseIf} $LANGUAGE == 1042
- StrCpy $0 "ko" ; Korean
- ${ElseIf} $LANGUAGE == 1088
- StrCpy $0 "ky" ; Kyrgyz (Cyrillic)
- ${ElseIf} $LANGUAGE == 1108
- StrCpy $0 "lo" ; Lao
- ${ElseIf} $LANGUAGE == 1142
- StrCpy $0 "la" ; Latin
- ${ElseIf} $LANGUAGE == 1062
- StrCpy $0 "lv" ; Latvian
- ${ElseIf} $LANGUAGE == 1063
- StrCpy $0 "lt" ; Lithuanian
- ${ElseIf} $LANGUAGE == 1086
- StrCpy $0 "ms" ; Malay - Malaysia
- ${ElseIf} $LANGUAGE == 2110
- StrCpy $0 "ms" ; Malay - Brunei Darussalam
- ${ElseIf} $LANGUAGE == 1100
- StrCpy $0 "ml" ; Malayalam
- ${ElseIf} $LANGUAGE == 1082
- StrCpy $0 "mt" ; Maltese
- ${ElseIf} $LANGUAGE == 1112
- StrCpy $0 "en" ; Manipuri (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1153
- StrCpy $0 "mi" ; Maori - New Zealand
- ${ElseIf} $LANGUAGE == 1102
- StrCpy $0 "mr" ; Marathi
- ${ElseIf} $LANGUAGE == 1104
- StrCpy $0 "mn" ; Mongolian (Cyrillic)
- ${ElseIf} $LANGUAGE == 2128
- StrCpy $0 "mn" ; Mongolian (Mongolian)
- ${ElseIf} $LANGUAGE == 1121
- StrCpy $0 "ne" ; Nepali
- ${ElseIf} $LANGUAGE == 2145
- StrCpy $0 "ne" ; Nepali - India
- ${ElseIf} $LANGUAGE == 1044
- StrCpy $0 "nb" ; Norwegian (Bokm
- ${ElseIf} $LANGUAGE == 2068
- StrCpy $0 "no" ; Norwegian (Nynorsk)
- ${ElseIf} $LANGUAGE == 1096
- StrCpy $0 "or" ; Oriya
- ${ElseIf} $LANGUAGE == 1138
- StrCpy $0 "om" ; Oromo
- ${ElseIf} $LANGUAGE == 1145
- StrCpy $0 "en" ; Papiamentu (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1123
- StrCpy $0 "ps" ; Pashto
- ${ElseIf} $LANGUAGE == 1045
- StrCpy $0 "pl" ; Polish
- ${ElseIf} $LANGUAGE == 1046
- StrCpy $0 "pt" ; Portuguese - Brazil
- ${ElseIf} $LANGUAGE == 2070
- StrCpy $0 "pt" ; Portuguese - Portugal
- ${ElseIf} $LANGUAGE == 1094
- StrCpy $0 "pa" ; Punjabi
- ${ElseIf} $LANGUAGE == 2118
- StrCpy $0 "pa" ; Punjabi (Pakistan)
- ${ElseIf} $LANGUAGE == 1131
- StrCpy $0 "qu" ; Quecha - Bolivia
- ${ElseIf} $LANGUAGE == 2155
- StrCpy $0 "qu" ; Quecha - Ecuador
- ${ElseIf} $LANGUAGE == 3179
- StrCpy $0 "qu" ; Quecha - Peru
- ${ElseIf} $LANGUAGE == 1047
- StrCpy $0 "rm" ; Rhaeto-Romanic
- ${ElseIf} $LANGUAGE == 1048
- StrCpy $0 "ro" ; Romanian
- ${ElseIf} $LANGUAGE == 2072
- StrCpy $0 "ro" ; Romanian - Moldava
- ${ElseIf} $LANGUAGE == 1049
- StrCpy $0 "ru" ; Russian
- ${ElseIf} $LANGUAGE == 2073
- StrCpy $0 "ru" ; Russian - Moldava
- ${ElseIf} $LANGUAGE == 1083
- StrCpy $0 "se" ; Sami (Lappish)
- ${ElseIf} $LANGUAGE == 1103
- StrCpy $0 "sa" ; Sanskrit
- ${ElseIf} $LANGUAGE == 1132
- StrCpy $0 "en" ; Sepedi (NOT FOUND)
- ${ElseIf} $LANGUAGE == 3098
- StrCpy $0 "sr" ; Serbian (Cyrillic)
- ${ElseIf} $LANGUAGE == 2074
- StrCpy $0 "sr" ; Serbian (Latin)
- ${ElseIf} $LANGUAGE == 1113
- StrCpy $0 "" ; Sindhi - India
- ${ElseIf} $LANGUAGE == 2137
- StrCpy $0 "sd" ; Sindhi - Pakistan
- ${ElseIf} $LANGUAGE == 1115
- StrCpy $0 "si" ; Sinhalese - Sri Lanka
- ${ElseIf} $LANGUAGE == 1051
- StrCpy $0 "sk" ; Slovak
- ${ElseIf} $LANGUAGE == 1060
- StrCpy $0 "sl" ; Slovenian
- ${ElseIf} $LANGUAGE == 1143
- StrCpy $0 "so" ; Somali
- ${ElseIf} $LANGUAGE == 1070
- StrCpy $0 "en" ; Sorbian (NOT FOUND)
- ${ElseIf} $LANGUAGE == 3082
- StrCpy $0 "es" ; Spanish - Spain (Modern Sort)
- ${ElseIf} $LANGUAGE == 1034
- StrCpy $0 "es" ; Spanish - Spain (Traditional Sort)
- ${ElseIf} $LANGUAGE == 11274
- StrCpy $0 "es" ; Spanish - Argentina
- ${ElseIf} $LANGUAGE == 16394
- StrCpy $0 "es" ; Spanish - Bolivia
- ${ElseIf} $LANGUAGE == 13322
- StrCpy $0 "es" ; Spanish - Chile
- ${ElseIf} $LANGUAGE == 9226
- StrCpy $0 "es" ; Spanish - Colombia
- ${ElseIf} $LANGUAGE == 5130
- StrCpy $0 "es" ; Spanish - Costa Rica
- ${ElseIf} $LANGUAGE == 7178
- StrCpy $0 "es" ; Spanish - Dominican Republic
- ${ElseIf} $LANGUAGE == 12298
- StrCpy $0 "es" ; Spanish - Ecuador
- ${ElseIf} $LANGUAGE == 17418
- StrCpy $0 "es" ; Spanish - El Salvador
- ${ElseIf} $LANGUAGE == 4106
- StrCpy $0 "es" ; Spanish - Guatemala
- ${ElseIf} $LANGUAGE == 18442
- StrCpy $0 "es" ; Spanish - Honduras
- ${ElseIf} $LANGUAGE == 58378
- StrCpy $0 "es" ; Spanish - Latin America
- ${ElseIf} $LANGUAGE == 2058
- StrCpy $0 "es" ; Spanish - Mexico
- ${ElseIf} $LANGUAGE == 19466
- StrCpy $0 "es" ; Spanish - Nicaragua
- ${ElseIf} $LANGUAGE == 6154
- StrCpy $0 "es" ; Spanish - Panama
- ${ElseIf} $LANGUAGE == 15370
- StrCpy $0 "es" ; Spanish - Paraguay
- ${ElseIf} $LANGUAGE == 10250
- StrCpy $0 "es" ; Spanish - Peru
- ${ElseIf} $LANGUAGE == 20490
- StrCpy $0 "es" ; Spanish - Puerto Rico
- ${ElseIf} $LANGUAGE == 21514
- StrCpy $0 "es" ; Spanish - United States
- ${ElseIf} $LANGUAGE == 14346
- StrCpy $0 "es" ; Spanish - Uruguay
- ${ElseIf} $LANGUAGE == 8202
- StrCpy $0 "es" ; Spanish - Venezuela
- ${ElseIf} $LANGUAGE == 1072
- StrCpy $0 "en" ; Sutu (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1089
- StrCpy $0 "sw" ; Swahili
- ${ElseIf} $LANGUAGE == 1053
- StrCpy $0 "sv" ; Swedish
- ${ElseIf} $LANGUAGE == 2077
- StrCpy $0 "sv" ; Swedish - Finland
- ${ElseIf} $LANGUAGE == 1114
- StrCpy $0 "en" ; Syriac (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1064
- StrCpy $0 "tg" ; Tajik
- ${ElseIf} $LANGUAGE == 1119
- StrCpy $0 "en" ; Tamazight (Arabic) (NOT FOUND)
- ${ElseIf} $LANGUAGE == 2143
- StrCpy $0 "en" ; Tamazight (Latin) (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1097
- StrCpy $0 "ta" ; Tamil
- ${ElseIf} $LANGUAGE == 1092
- StrCpy $0 "tt" ; Tatar
- ${ElseIf} $LANGUAGE == 1098
- StrCpy $0 "te" ; Telugu
- ${ElseIf} $LANGUAGE == 1054
- StrCpy $0 "th" ; Thai
- ${ElseIf} $LANGUAGE == 2129
- StrCpy $0 "bo" ; Tibetan - Bhutan
- ${ElseIf} $LANGUAGE == 1105
- StrCpy $0 "bo" ; Tibetan - People's Republic of China
- ${ElseIf} $LANGUAGE == 2163
- StrCpy $0 "ti" ; Tigrigna - Eritrea
- ${ElseIf} $LANGUAGE == 1139
- StrCpy $0 "ti" ; Tigrigna - Ethiopia
- ${ElseIf} $LANGUAGE == 1073
- StrCpy $0 "ts" ; Tsonga
- ${ElseIf} $LANGUAGE == 1074
- StrCpy $0 "tn" ; Tswana
- ${ElseIf} $LANGUAGE == 1055
- StrCpy $0 "tr" ; Turkish
- ${ElseIf} $LANGUAGE == 1090
- StrCpy $0 "tk" ; Turkmen
- ${ElseIf} $LANGUAGE == 1152
- StrCpy $0 "ug" ; Uighur - China
- ${ElseIf} $LANGUAGE == 1058
- StrCpy $0 "ug" ; Ukrainian
- ${ElseIf} $LANGUAGE == 1056
- StrCpy $0 "ur" ; Urdu
- ${ElseIf} $LANGUAGE == 2080
- StrCpy $0 "ur" ; Urdu - India
- ${ElseIf} $LANGUAGE == 2115
- StrCpy $0 "uz" ; Uzbek (Cyrillic)
- ${ElseIf} $LANGUAGE == 1091
- StrCpy $0 "uz" ; Uzbek (Latin)
- ${ElseIf} $LANGUAGE == 1075
- StrCpy $0 "ve" ; Venda
- ${ElseIf} $LANGUAGE == 1066
- StrCpy $0 "vi" ; Vietnamese
- ${ElseIf} $LANGUAGE == 1106
- StrCpy $0 "cy" ; Welsh
- ${ElseIf} $LANGUAGE == 1076
- StrCpy $0 "xh" ; Xhosa
- ${ElseIf} $LANGUAGE == 1144
- StrCpy $0 "en" ; Yi (NOT FOUND)
- ${ElseIf} $LANGUAGE == 1085
- StrCpy $0 "yi" ; Yiddish
- ${ElseIf} $LANGUAGE == 1130
- StrCpy $0 "yo" ; Yoruba
- ${ElseIf} $LANGUAGE == 1077
- StrCpy $0 "zu" ; Zulu
- ${Else}
- StrCpy $0 "en" ; English is our backup
- ${Endif}
-FunctionEnd
-
-SetPluginUnload alwaysoff
-
-!macro CheckNoCandy
- ;Fills $0 with 0 if not found 1 if found
- push $1
- push $2
- push $3
- ${GetParameters} $0
-
- StrLen $1 $0 ;$1 Len of str
- IntOp $2 0 + 0 ;offset
-
-OCLookForNoCandy:
- StrCpy $3 $0 8 $2
- StrCmp $3 "/NOCANDY" OCFoundNoCandy
- IntCmp $2 $1 OCNoCandyNotHere 0 OCNoCandyNotHere
- IntOp $2 $2 + 1
- Goto OCLookForNoCandy
-
-OCFoundNoCandy:
- IntOp $0 0 + 1
- IntOp $OCNoCandy 0 + 1
- Goto OCNoCandyDone
-
-OCNoCandyNotHere:
- IntOp $0 0 + 0
- IntOp $OCNoCandy 0 + 0
-
-OCNoCandyDone:
- pop $3
- pop $2
- pop $1
+!macro _OpenCandyAPIInserted APINAME
+ ; Add a definition to note insertion of API name
+ !ifndef _OC_APICHECK_INSERTED_${APINAME}
+ !define _OC_APICHECK_INSERTED_${APINAME}
+ !endif
!macroend
-!macro GetCandyParameter
- ;Fills $0 with "" if not found OID if found
- push $1
- push $2
- push $3
- push $4
- ${GetParameters} $0
- StrLen $1 $0 ;$1 Len of str
- IntOp $2 0 + 0 ;offset
-
-OCLookForCandyRX:
- StrCpy $3 $0 8 $2
- StrCmp $3 "/CANDYRX" OCFoundCandyRX
- IntCmp $2 $1 OCCandyRXNotHere 0 OCCandyRXNotHere
- IntOp $2 $2 + 1
- Goto OCLookForCandyRX
-
-OCFoundCandyRX:
- IntOp $1 $1 - $2
- StrCpy $3 $0 $1 $2
-
- ;trim anything past a space if found
- IntOp $2 0 + 0
- StrCpy $0 ""
-
-OCCandyRxSpaceSearch:
- StrCpy $4 $3 1 $2
- StrCmp $4 " " OCCandyRXDone
- IntOp $2 $2 + 1
+!macro _OpenCandyAPICheckInserted APINAME WARNMSG
+ ; Check an API name was inserted, show a warning otherwise
+ !ifndef _OC_APICHECK_INSERTED_${APINAME}
+ !if "${WARNMSG}" != ""
+ !warning "Did not find reference to required API ${APINAME}. ${WARNMSG}"
+ !else
+ !warning "Did not find reference to required API ${APINAME}."
+ !endif
+ !endif
+!macroend
- ;copy what we got so far
- StrCpy $0 $3 $2
-
- IntCmp $2 $1 OCCandyRXDone OCCandyRxSpaceSearch OCCandyRXDone
+!macro OpenCandyAPIDoChecks
+ ; Check only for mandatory API names
+ !insertmacro _OpenCandyAPICheckInserted _OpenCandyInitInternal "Check that you have inserted OpenCandyAsyncInit in your .onInit callback function, after any language selection code."
+ !insertmacro _OpenCandyAPICheckInserted OpenCandyOfferPage "Check that you have inserted OpenCandyOfferPage in your list of installer pages (e.g. before instfiles)."
+ !insertmacro _OpenCandyAPICheckInserted OpenCandyOnInstSuccess "Check that you have inserted OpenCandyOnInstSuccess in your .onInstSuccess callback function."
+ !insertmacro _OpenCandyAPICheckInserted OpenCandyOnGuiEnd "Check that you have inserted OpenCandyOnGuiEnd in your .onGUIEnd callback function."
+ !insertmacro _OpenCandyAPICheckInserted OpenCandyInstallDll "Check that you have inserted OpenCandyInstallDll in a section that will run during your product installation."
+!macroend
-OCCandyRXNotHere:
- StrCpy $0 ""
-OCCandyRXDone:
- pop $4
- pop $3
- pop $2
- pop $1
+;
+; OpenCandyReserveFile
+; --------------------
+; Insert this macro as close to the top of your .nsi file as possible
+; after including this header, before other functions and sections that
+; include "File" directives. This will reserve a place early in the
+; file datablock for OCSetupHlp.dll. Because the DLL is required in
+; the .onInit callback function the reservation will make your installer
+; launch faster and allow more time for fetching offer information.
+;
+; ; Improve startup performance and increase offer fetch time by
+; ; reserving an early place in the file data block for OpenCandy DLL.
+; !insertmacro OpenCandyReserveFile
+;
+!macro OpenCandyReserveFile
+ ReserveFile "${OC_OCSETUPHLP_FILE_PATH}"
!macroend
-!macro OpenCandyInitInternal PublisherName Key Secret Location
- ; -------------------------- OS CHECK -----------------------
- Push $R0
- Push $R1
-
- IntOp $OCOSSupported 0 + 0
-
- ClearErrors
-
- ReadRegStr $R0 HKLM \
- "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
-
- IfErrors 0 lbl_winnt
-
- ; we are not NT
- GoTo lbl_error
-
- lbl_winnt:
-
- StrCpy $R1 $R0 1
-
- StrCmp $R1 '3' lbl_done
- StrCmp $R1 '4' lbl_done
-
- StrCpy $R1 $R0 3
-
- StrCmp $R1 '5.0' lbl_error
- StrCmp $R1 '5.1' lbl_done
- StrCmp $R1 '5.2' lbl_done
- StrCmp $R1 '6.0' lbl_done
- StrCmp $R1 '6.1' lbl_done
-
- lbl_error:
- IntOp $OCOSSupported 0 + 1
-
- lbl_done:
-
- Pop $R1
- Pop $R0
- IntOP $OCUseOfferPage 0 + 0
- IntOP $OCInitcode 0 + 0
- ; -------------------------- OS CHECK -----------------------
-
- ${If} $OCOSSupported == 0
-
- ; We need to be loaded throughout the setup
- ; as we will uload ourselves when necessary
-
- Push $0
- Push $1
- Push $2
- Push $3
- Push $4
- Push $5
-
- IntOp $OCDetached 0 + 1
- StrCpy $OCProductKey "${Key}"
-
- !insertmacro CheckNoCandy
-
- IntOp $4 $0 + 0
- IntOp $5 $0 + 0
-
- ${If} $OCRemnant == 0
-
- ${If} $4 == 0
- StrCpy $0 "${PublisherName}" ; Publisher
-
- StrCpy $1 "${Key}" ; Product "Key"
- StrCpy $2 "${Secret}" ; Secret
-
- ; Get installer language
-
- Push $0
- Call GetLanguageString
- StrCpy $3 $0
- Pop $0
-
- StrCpy $4 "${Location}" ;Registry location
-
- InitPluginsDir
- SetOutPath "$PLUGINSDIR"
- File "OCSetupHlp.dll"
+;
+; _OpenCandyDevModeMsg
+; --------------------
+; This macro is internal to this helper script. Do not
+; insert it in your own code.
+;
+; The macro code is intentionally unguarded with respect
+; to $OCHasBeenInitialized and $OCHasBeenInitialized. Calling
+; code is responsible for ensuring appropriate conditions.
+;
+; Parameters:
+;
+; OC_DEV_MSG : Message to display (string)
+; OC_DEV_ERROR : The message represents an error OC_NSIS_TRUE or OC_NSIS_FALSE
+; OC_FAQ_ID : ID of the FAQ associated with the message, or 0 if there is no FAQ associated (int)
+;
+; Usage:
+;
+; !insertmacro _OpenCandyDevModeMsg "This is an error with associated FAQ #500" ${OC_NSIS_TRUE} 500
+;
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCInit2A(m, m, m, m, m)i(r0, r1, r2 ,r3 ,r4).r5? c'
-!else
- System::Call 'OCSetupHlp::OCInit2A(t, t, t, t, t)i(r0, r1, r2 ,r3 ,r4).r5? c'
-!endif
- ${Else}
-
- !insertmacro GetCandyParameter
- StrCpy $1 $0
-
- StrCpy $0 "${Location}" ;Registry location
- StrCpy $2 "${Key}"
-
- InitPluginsDir
- SetOutPath "$PLUGINSDIR"
- File "OCSetupHlp.dll"
+!macro _OpenCandyDevModeMsg OC_DEV_MSG OC_DEV_ERROR OC_FAQ_ID
+ Push $0
+ StrCpy $0 "${OC_DEV_MSG}"
+ !if ${OC_DEV_ERROR} == ${OC_NSIS_TRUE}
+ !define OC_TMP_DEV_ERROR ${OC_DEVMSG_ERROR_TRUE}
+ StrCpy $0 "{\rtf1 {\colortbl;\red0\green0\blue0;\red255\green0\blue0;}\cf2Status ERROR! \cf1 $0\par}"
+ !else if ${OC_DEV_ERROR} == ${OC_NSIS_FALSE}
+ !define OC_TMP_DEV_ERROR ${OC_DEVMSG_ERROR_FALSE}
+ !else
+ !error "Value for OC_DEV_ERROR must be either OC_NSIS_TRUE or OC_NSIS_FALSE!"
+ !endif
+ !ifdef NSIS_UNICODE
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237LogDevModeMessageW(w, i, i)(r0, ${OC_TMP_DEV_ERROR}, ${OC_FAQ_ID})? c"
+ !else
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237LogDevModeMessage(m, i, i)(r0, ${OC_TMP_DEV_ERROR}, ${OC_FAQ_ID})? c"
+ !endif
+ Pop $0
+ !undef OC_TMP_DEV_ERROR
+!macroend
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCSetOfferLocation(m, m, m)i(r0, r1, r2).r3? c'
-!else
- System::Call 'OCSetupHlp::OCSetOfferLocation(t, t, t)i(r0, r1, r2).r3? c'
-!endif
- IntOp $5 0 + 1
-
- ${endif}
- IntOp $OCInitcode 0 + $5
- ${If} $5 == 0
- IntOp $OCUseOfferPage 1 + 0
-!ifdef NSIS_UNICODE
+;
+; _OpenCandyInitChecksAndDefaults
+; -------------------------------
+; This macro is internal to this helper script. Do not
+; insert it in your own code.
+;
- Push $3
- Push $4
- Push $5
+!macro _OpenCandyInitChecksAndDefaults
+ !ifdef _OpenCandyInitChecksAndDefaults
+ !error "_OpenCandyInitChecksAndDefaults inserted more than once"
+ !else
+ !define _OpenCandyInitChecksAndDefaults
+
+ ; Compile-time checks and defaults
+ !if "${PublisherName}" == "${OC_SAMPLE_PUBLISHERNAME}"
+ !warning "Do not forget to change the product name from '${OC_SAMPLE_PUBLISHERNAME}' to your company's product name before releasing this installer."
+ !endif
+ !if "${Key}" == "${OC_SAMPLE_KEY}"
+ !warning "Do not forget to change the sample key '${OC_SAMPLE_KEY}' to your company's product key before releasing this installer."
+ !endif
+ !if "${Secret}" == "${OC_SAMPLE_SECRET}"
+ !warning "Do not forget to change the sample secret '${OC_SAMPLE_SECRET}' to your company's product secret before releasing this installer."
+ !endif
+
+ ; DLL relocation support
+ !ifndef OC_OCSETUPHLP_FILE_PATH
+ !warning "Do not forget to define OC_OCSETUPHLP_FILE_PATH in your script. Defaulting to 'OCSetupHlp.dll'."
+ !define OC_OCSETUPHLP_FILE_PATH ".\OCSetupHlp.dll"
+ !endif
+
+ ; OC_MAX_INIT_TIME is the maximum time in milliseconds that OCInit may block when fetching offers.
+ ; Note that under normal network conditions OCInit may return sooner. Setting this value too low
+ ; may reduce offer rate. Values of 5000 or greater are recommended. If you intend to override this
+ ; default do so by defining it in your .nsi file before #include'ing this header. Be certain to
+ ; make OpenCandy partner support aware of any override you apply because this can affect your metrics.
+ !ifndef OC_MAX_INIT_TIME
+ !define OC_MAX_INIT_TIME 8000
+ !endif
- System::Alloc /NOUNLOAD 1024
- Pop $4
- System::Alloc /NOUNLOAD 1024
- Pop $5
+ !endif
+!macroend
- System::Call /NOUNLOAD 'OCSetupHlp::OCGetBannerInfo(i, i)i(r4, r5).r2? c'
- System::Call /NOUNLOAD 'kernel32::MultiByteToWideChar(i 65001, i 0, i r4, i -1, t .r0, i 1024) i .r3'
- System::Call /NOUNLOAD 'kernel32::MultiByteToWideChar(i 65001, i 0, i r5, i -1, t .r1, i 1024) i .r3'
- System::Free /NOUNLOAD $4
- System::Free $5
+;
+; _OpenCandyInitInternal
+; ----------------------
+; This macro is internal to this helper script. Do not
+; insert it in your own code. Instead see OpenCandyInit
+; and OpenCandyAsyncInit.
+;
+
+!macro _OpenCandyInitInternal
+!insertmacro _OpenCandyAPIInserted _OpenCandyInitInternal
+${If} $OCHasBeenInitialized <> ${OC_NSIS_TRUE}
+
+ Exch $0 ; Publisher name
+ Exch 1
+ Exch $1 ; Key
+ Exch 2
+ Exch $2 ; Secret
+ Exch 3
+ Exch $3 ; Enable Async
+ Exch 4
+ Exch $4 ; Init mode
+ Push $5 ; Language
+ StrCpy $5 $LANGUAGE
+
+ ; Check macro definitions and enforce defaults
+ !insertmacro _OpenCandyInitChecksAndDefaults
- Pop $5
- Pop $4
- Pop $3
+ ; Initialize OpenCandy variables
+ StrCpy $OCNoCandy ${OC_NSIS_FALSE}
+ StrCpy $OCUseOfferPage ${OC_NSIS_FALSE}
+ StrCpy $OCHasReachedOCPage ${OC_NSIS_FALSE}
+ StrCpy $OCHasBeenInitialized ${OC_NSIS_FALSE}
+ StrCpy $OCProductInstallSuccess ${OC_NSIS_FALSE}
+ StrCpy $OCAttached ${OC_NSIS_FALSE}
+
+ ; Unpack and load the OpenCandy SDK DLL
+ InitPluginsDir
+ IfFileExists "$PLUGINSDIR\OCSetupHlp.dll" OCDLLExists
+ File "/oname=$PLUGINSDIR\OCSetupHlp.dll" "${OC_OCSETUPHLP_FILE_PATH}"
+ OCDLLExists:
+ ClearErrors
+ Push $0
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237LoadOpenCandyDLL()i().r0? c"
+ IfErrors OCDLLoadFailed ; System plugin failed
+ ${if} $0 == error ; API call failed
+ ${orif} $0 == ${OC_LOADOCDLL_FAILURE} ; API returned failure
+ Goto OCDLLoadFailed
+ ${endif}
+ Goto OCDLLoadSuccess
+ OCDLLoadFailed:
+ StrCpy $OCNoCandy ${OC_NSIS_TRUE}
+ OCDLLoadSuccess:
+ Pop $0
-!else
- System::Call 'OCSetupHlp::OCGetBannerInfo(t, t)i(.r0, .r1).r2? c'
-!endif
- ${If} $2 == 3
- StrCpy $OCPageTitle $0
- StrCpy $OCPageDesc $1
- ${ElseIf} $2 == 1
- StrCpy $OCPageDesc " "
- ${ElseIf} $2 == 2
- StrCpy $OCPageTitle " "
- ${Else}
- StrCpy $OCPageTitle " "
- StrCpy $OCPageDesc " "
- ${EndIf}
- ${Else}
-
- IntOp $OCUseOfferPage 0 + 0
- SetPluginUnload manual
- ; Do nothing (but let the installer unload the System dll)
- System::Free 0
- ${EndIf}
-
- ${EndIf}
-
- Pop $5
- Pop $4
- Pop $3
- Pop $2
- Pop $1
- Pop $0
-
- ${endif}
-
+ ; Handle command line options and silent installations
+ ${if} $OCNoCandy == ${OC_NSIS_FALSE}
+ Push $0
+ Push $1
+ ${GetParameters} $0
+ IfSilent 0 OCNotSilent ; Force /NOCANDY if this is a silent install
+ StrCpy $0 "/NOCANDY"
+ OCNotSilent:
+
+ !ifdef NSIS_UNICODE
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237SetCmdLineValuesW(w)i(r0).r1? c"
+ !else
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237SetCmdLineValues(m)i(r0).r1? c"
+ !endif
+
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237GetNoCandy()i().r1? c"
+ ${if} $1 == ${OC_CANDY_DISABLED}
+ StrCpy $OCNoCandy ${OC_NSIS_TRUE}
+ ${endif}
+ Pop $1
+ Pop $0
+ ${endif}
+
+ ; Pass publisher details to OpenCandy API
+ ${if} $OCNoCandy == ${OC_NSIS_FALSE}
+ ${if} $4 == ${OC_NSIS_TRUE}
+ StrCpy $4 ${OC_INIT_ASYNC_ENABLE}
+ ${elseif} $4 == ${OC_NSIS_FALSE}
+ StrCpy $4 ${OC_INIT_ASYNC_DISABLE}
+ ${else}
+ !insertmacro _OpenCandyDevModeMsg "OCSetupHlp.nsh - Init: Value for Async must be either OC_NSIS_TRUE or OC_NSIS_FALSE." ${OC_NSIS_TRUE} 0
+ StrCpy $4 ${OC_INIT_ASYNC_ENABLE} ; Failsafe
+ ${endif}
+
+ !ifdef NSIS_UNICODE
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237Init2W(w, w, w, w, i, i, i)i(r0, r1, r2, r5, r3, ${OC_MAX_INIT_TIME}, r4).s? c"
+ !else
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237Init2A(m, m, m, m, i, i, i)i(r0, r1, r2, r5, r3, ${OC_MAX_INIT_TIME}, r4).s? c"
+ !endif
+
+ Exch $0
+ ${if} $0 == ${OC_INIT_SUCCESS}
+ StrCpy $OCHasBeenInitialized ${OC_NSIS_TRUE}
+ ${endif}
+ Pop $0
+ ${endif}
+
+ Pop $5
+ Pop $4
+ Pop $0
+ Pop $1
+ Pop $2
+ Pop $3
+${endif}
!macroend
-;
-; Install Functions
-; -----------------
-;
+
;
-; OpenCandyInit
-;
+; OpenCandyInit (Deprecated) / OpenCandyAsyncInit
+; -----------------------------------------------
; Performs initialization of the OpenCandy DLL
-; and checks for available offers to present.
-;
-; Parameters are:
+; and checks for offers to present.
;
-; PublisherName : Your publisher name (will be provided by OpenCandy)
-; Key : Your product key (will be provided by OpenCandy)
-; Secret : Your product code (will be provided by OpenCandy)
-; Location : A registry path for us to store state information in (will be provided by OpenCandy)
+; Parameters:
;
+; PublisherName : Your publisher name (will be provided by OpenCandy)
+; Key : Your product key (will be provided by OpenCandy)
+; Secret : Your product secret (will be provided by OpenCandy)
+; InitMode : The operating mode. Pass OC_INIT_MODE_NORMAL for normal operation
+; or OC_INIT_MODE_REMNANT if OpenCandy should not show offers. Do not
+; use InitMode to handle /NOCANDY, this is done automatically for you.
+;
+; Usage (Using sample values for internal testing purposes only):
+;
+; ; Initialize OpenCandy, check for offers
+; ;
+; ; Note: If you use a language selection system,
+; ; e.g. MUI_LANGDLL_DISPLAY or calls to LangDLL, you must insert
+; ; this macro after the language selection code in order for
+; ; OpenCandy to detect the user-selected language.
+; !insertmacro OpenCandyAsyncInit "Open Candy Sample" 748ad6d80864338c9c03b664839d8161 dfb3a60d6bfdb55c50e1ef53249f1198 ${OC_INIT_MODE_NORMAL}
+;
+
+!macro OpenCandyInit PublisherName Key Secret InitMode
+ Push ${InitMode}
+ Push ${OC_NSIS_FALSE} ; Enable Async?
+ Push ${Secret}
+ Push ${Key}
+ Push "${PublisherName}"
+ !insertmacro _OpenCandyInitInternal
+!macroend
-!macro OpenCandyInit PublisherName Key Secret Location
+!macro OpenCandyAsyncInit PublisherName Key Secret InitMode
+ Push ${InitMode}
+ Push ${OC_NSIS_TRUE} ; Enable Async?
+ Push ${Secret}
+ Push ${Key}
+ Push "${PublisherName}"
+ !insertmacro _OpenCandyInitInternal
+!macroend
- IntOp $OCRemnant 0 + 0
- !insertmacro OpenCandyInitInternal "${PublisherName}" "${Key}" "${Secret}" "${Location}"
-!macroend
;
-; OpenCandyInitRemnant
+; SetOCOfferEnabled
+; -----------------
+; Allows you to disable the OpenCandy offer screen easily from your
+; installer code. Note that this is not the recommended method - you
+; ought to determine during initialization whether OpenCandy should be
+; disabled and specify an appropriate mode when inserting OpenCandyInit
+; or OpenCandyAsyncInit in that case. If you must use this method please
+; be sure to inform the OpenCandy partner support team. Never directly
+; place logical conditions around other OpenCandy functions and macros because
+; this can have unforseen consequences. You should call this procedure only
+; after calling OpenCandyInit / OpenCandyAsyncInit.
+;
+; Usage:
;
-; Performs initialization of the OpenCandy DLL
-; and checks for available offers to present.
+; # This turns off offers from the OpenCandy network
+; !insertmacro SetOCOfferEnabled ${OC_NSIS_FALSE}
;
-; This function is similar to the previous one
-; but allow to specify whrether to show the offer
-; page or not (last parameter). This should be used
-; when a primary offer (such as a toolbar) also
-; exists and OC should not be shown.
+
+!macro SetOCOfferEnabled OC_OFFER_ENABLED
+${If} $OCHasBeenInitialized == ${OC_NSIS_TRUE}
+${AndIf} $OCNoCandy == ${OC_NSIS_FALSE}
+ !if ${OC_OFFER_ENABLED} == ${OC_NSIS_TRUE}
+ !define OC_TMP_OFFER_ENABLED ${OC_OFFER_ENABLE_TRUE}
+ !else if ${OC_OFFER_ENABLED} == ${OC_NSIS_FALSE}
+ !define OC_TMP_OFFER_ENABLED ${OC_OFFER_ENABLE_FALSE}
+ !else
+ !error "Value for OC_OFFER_ENABLED must be either OC_NSIS_TRUE or OC_NSIS_FALSE!"
+ !endif
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237SetOCOfferEnabled(i)(${OC_TMP_OFFER_ENABLED})? c"
+ !undef OC_TMP_OFFER_ENABLED
+${EndIf}
+!macroend
+
+
+
;
-; Parameters are:
+; GetOCOfferStatus
+; ----------------
+; Allows you to determine if an offer is currently available. This is
+; done automatically for you before the offer screen is shown. Typically
+; you do not need to call this function from your own code directly.
+;
+; The offer status is placed on the stack and may be one of:
+; ${OC_OFFER_STATUS_CANOFFER_READY} - An OpenCandy offer is available and ready to be shown
+; ${OC_OFFER_STATUS_CANOFFER_NOTREADY} - An offer is available but is not yet ready to be shown
+; ${OC_OFFER_STATUS_QUERYING_NOTREADY} - The remote API is still being queried for offers
+; ${OC_OFFER_STATUS_NOOFFERSAVAILABLE} - No offers are available
+;
+; When using the macro you must indicate whether the information returned
+; will be used to decide whether the OpenCandy offer screen will be shown, e.g.
+; if the information may result in use of the SetOCOfferEnabled macro. This helps
+; to optimize future OpenCandy SDKs for better performance with your product.
;
-; PublisherName : Your publisher name (will be provided by OpenCandy)
-; Key : Your product key (will be provided by OpenCandy)
-; Secret : Your product code (will be provided by OpenCandy)
-; Location : A registry path for us to store state information (will be provided by OpenCandy)
-; DontShowOC : Pass 1 to NOT show the offer screen (primary offer is shown instead)
-; Pass 0 to SHOW the OC page (primary offer is not shown)
+; Usage:
;
+; # Test if OpenCandy is ready to show an offer.
+; # Indicate the result is informative only and does not directly
+; # determine whether offers from OpenCandy are enabled.
+; !insertmacro GetOCOfferStatus ${OC_NSIS_FALSE}
+; Pop <result>
+;
+
+!macro GetOCOfferStatus OC_DETERMINES_OFFER_ENABLED
+${If} $OCHasBeenInitialized == ${OC_NSIS_TRUE}
+${AndIf} $OCNoCandy == ${OC_NSIS_FALSE}
+ !if ${OC_DETERMINES_OFFER_ENABLED} == ${OC_NSIS_TRUE}
+ !define OC_TMP_DETERMINES_OFFER_ENABLED ${OC_STATUS_QUERY_DETERMINESOFFERENABLED}
+ !else if ${OC_DETERMINES_OFFER_ENABLED} == ${OC_NSIS_FALSE}
+ !define OC_TMP_DETERMINES_OFFER_ENABLED ${OC_STATUS_QUERY_GENERAL}
+ !else
+ !error "Value for OC_DETERMINES_OFFER_ENABLED must be either OC_NSIS_TRUE or OC_NSIS_FALSE!"
+ !endif
+ Push $0
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237GetAsyncOfferStatus(i)i(${OC_TMP_DETERMINES_OFFER_ENABLED}).r0? c"
+ Exch $0
+ !undef OC_TMP_DETERMINES_OFFER_ENABLED
+${Else}
+ Push ${OC_OFFER_STATUS_NOOFFERSAVAILABLE}
+${EndIf}
+!macroend
-!macro OpenCandyInitRemnant PublisherName Key Secret Location DontShowOC
-
- IntOp $OCRemnant 0 + 0
- ${If} $DontShowOC == 1
- IntOp $OCRemnant 1 + 0
- ${Endif}
- !insertmacro OpenCandyInitInternal "${PublisherName}" "${Key}" "${Secret}" "${Location}"
+;
+; OpenCandyOfferPage
+; ------------------
+; Inserts the OpenCandy offer page. The offer page will show
+; only if an offer is available and ready to be shown when
+; the user reaches the page.
+;
+; Usage:
+;
+; # Insert the OpenCandy offer page
+; !insertmacro OpenCandyOfferPage
+;
+!macro OpenCandyOfferPage
+ !insertmacro _OpenCandyAPIInserted OpenCandyOfferPage
+ PageEx custom
+ PageCallbacks _OpenCandyPageStartFn _OpenCandyPageLeaveFn
+ PageExEnd
!macroend
+
;
-; OpenCandyPageStartFn
-; --------------------
+; _OpenCandyPageStartFn
+; ---------------------
+; Decides if there is an offer to show and if so sets up
+; the offer page for NSIS.
;
-; Decides if there is an offer to show and
-; if so, sets up the offer page for NSIS
+; Do not call this function directly, it is a callback used
+; by the PageEx that is added to your .nsi script.
;
-; You do not need to call this function, it just
-; needs to be a parameter to the custom page
-; declared in your setup along with your other pages
+; Usage:
+;
+; # Insert the OpenCandy offer page
+; !insertmacro OpenCandyOfferPage
;
-Function OpenCandyPageStartFn
+Function _OpenCandyPageStartFn
+${If} $OCHasBeenInitialized == ${OC_NSIS_TRUE}
+${AndIf} $OCNoCandy == ${OC_NSIS_FALSE}
- ${If} $OCOSSupported == 0
- Push $0
-
- ${If} $OCRemnant == 1
- Abort
- ${EndIf}
-
- ${If} $OCUseOfferPage == 1
-
- ${If} $OCDetached == 0
- System::Call 'OCSetupHlp::OCDetach()i.r0? c'
- IntOp $OCDetached 0 + 1
+ Push $0
+
+ ${If} $OCAttached == ${OC_NSIS_TRUE}
+ System::Call "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237Detach()i.r0? c"
+ StrCpy $OCAttached ${OC_NSIS_FALSE}
+ ${EndIf}
+
+ ${If} $OCHasReachedOCPage == ${OC_NSIS_FALSE}
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237GetAsyncOfferStatus(i)i(${OC_STATUS_QUERY_DETERMINESOFFERENABLED}).r0? c"
+ ${If} $0 == ${OC_OFFER_STATUS_CANOFFER_READY}
+ StrCpy $OCUseOfferPage ${OC_NSIS_TRUE}
${EndIf}
+ ${EndIf}
+
+ StrCpy $OCHasReachedOCPage ${OC_NSIS_TRUE}
+
+ ${If} $OCUseOfferPage == ${OC_NSIS_TRUE}
+ ; Call OCGetBannerInfo to get title and description strings for the offer screen
+ !ifdef NSIS_UNICODE
+ !define OC_TMP_STRTYPE w
+ !else
+ !define OC_TMP_STRTYPE m
+ !endif
+ Push $1
+ Push $2
+ Push $3
+ Push $4
+ System::Call "*(&${OC_TMP_STRTYPE}${OC_STR_CHARS} '') i .r3" ; $1 points to OC_STR_CHARS chars of initialized memory
+ System::Call "*(&${OC_TMP_STRTYPE}${OC_STR_CHARS} '') i .r4" ; $2 points to OC_STR_CHARS chars of initialized memory
+ !ifdef NSIS_UNICODE
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237GetBannerInfoW(i, i)i(r3, r4).r0? c"
+ !else
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237GetBannerInfo(i, i)i(r3, r4).r0? c"
+ !endif
+
+ ; Override defaults based on what OCGetBannerInfo has filled
+ StrCpy $1 " "
+ StrCpy $2 " "
+ ${If} $0 == ${OC_OFFER_BANNER_FOUNDBOTH}
+ System::Call "*$3(&${OC_TMP_STRTYPE}${OC_STR_CHARS} .s)"
+ Pop $1
+ System::Call "*$4(&${OC_TMP_STRTYPE}${OC_STR_CHARS} .s)"
+ Pop $2
+ ${ElseIf} $0 == ${OC_OFFER_BANNER_FOUNDTITLE}
+ System::Call "*$3(&${OC_TMP_STRTYPE}${OC_STR_CHARS} .s)"
+ Pop $1
+ ${ElseIf} $0 == ${OC_OFFER_BANNER_FOUNDDESCRIPTION}
+ System::Call "*$4(&${OC_TMP_STRTYPE}${OC_STR_CHARS} .s)"
+ Pop $2
+ ${EndIf}
+ System::Free $4
+ System::Free $3
+ Pop $4
+ Pop $3
+ !undef OC_TMP_STRTYPE
+ ; Create and show offer page
nsDialogs::Create /NOUNLOAD 1018
- Pop $OCDialog
-
- ${If} $OCDialog == error
+ Exch $3
+ ${If} $3 == error
+ StrCpy $OCUseOfferPage ${OC_NSIS_FALSE}
+ Pop $3
+ Pop $2
+ Pop $1
+ Pop $0
Abort
${Else}
-
-!ifndef NSIS_UNICODE
- Push $OCPageTitle
- Push "65001"
- Push $LANGUAGE
- Call ConvertMultiByte
- Pop $OCPageTitle
-
- Push $OCPageDesc
- Push "65001"
- Push $LANGUAGE
- Call ConvertMultiByte
- Pop $OCPageDesc
-!endif
-
- !insertmacro MUI_HEADER_TEXT $OCPageTitle $OCPageDesc
-
- IntOp $OCDetached 0 + 0
-
- ; Check for PP and TOU links
-
- Push $1
- Push $2
- Push $3
- Push $4
- Push $5
- Push $6
- Push $7
-
- StrCpy $1 "PP"
- StrCpy $2 " "
-
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCCheckForLink(m,m)i(r1,.r2).r0? c'
-!else
- System::Call 'OCSetupHlp::OCCheckForLink(t,t)i(r1,.r2).r0? c'
-!endif
-
- ; Create dummy label
- ${NSD_CreateLink} 0 0 0 12u $2
- Pop $6
-
- ${If} $0 == 1
-
- ; Calculate the length of the text
-
- SendMessage $6 ${WM_GETFONT} 0 0 $5
- System::Call 'user32::GetDC(i)i(r6)i.r4'
- System::Call 'gdi32::SelectObject(i,i)i(r4,r5)i.r5'
- StrLen $3 $2
- System::Call *(i,i)i.r7
- System::Call 'gdi32::GetTextExtentPoint32(i,t,i,i)i(r4,r2,r3,r7)i.r0'
- System::Call *$7(i.r3,i)
- IntOp $3 $3 + 5 ;add a little padding
- System::Free $7
- System::Call 'gdi32::SelectObject(i,i)i(r4,r5)i.r0'
- System::Call 'user32::ReleaseDC(i,i)i(r6,r4)i.r0'
-
- ; Get positionning
-
- StrCpy $1 "PP"
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCGetLinkPlacementX(m)i(r1).r4? c'
- System::Call 'OCSetupHlp::OCGetLinkPlacementY(m)i(r1).r5? c'
-!else
- System::Call 'OCSetupHlp::OCGetLinkPlacementX(t)i(r1).r4? c'
- System::Call 'OCSetupHlp::OCGetLinkPlacementY(t)i(r1).r5? c'
-!endif
- ; And create the final label now
-
- ${If} $4 != -1
- ${AndIf} $5 != -1
- ${NSD_CreateLink} $4 $5 $3 12u $2
- ${Else}
- ; Default positionning
- ${NSD_CreateLink} 0 176 $3 12u $2
- ${EndIf}
- Pop $OCPPLabel
- ${NSD_OnClick} $OCPPLabel OCPPLabelClick
- ${EndIf}
-
- StrCpy $1 "TOU"
- StrCpy $2 " "
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCCheckForLink(m,m)i(r1,.r2).r0? c'
-!else
- System::Call 'OCSetupHlp::OCCheckForLink(t,t)i(r1,.r2).r0? c'
-!endif
- ${If} $0 == 1
-
- ; Calculate the length of the text
-
- SendMessage $6 ${WM_GETFONT} 0 0 $5
- System::Call 'user32::GetDC(i)i(r6)i.r4'
- System::Call 'gdi32::SelectObject(i,i)i(r4,r5)i.r5'
- StrLen $3 $2
- System::Call *(i,i)i.r7
- System::Call 'gdi32::GetTextExtentPoint32(i,t,i,i)i(r4,r2,r3,r7)i.r0'
- System::Call *$7(i.r3,i)
- IntOp $3 $3 + 5 ;add a little padding
- System::Free $7
- System::Call 'gdi32::SelectObject(i,i)i(r4,r5)i.r0'
- System::Call 'user32::ReleaseDC(i,i)i(r6,r4)i.r0'
-
- ; Get positionning
-
- StrCpy $1 "TOU"
-
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCGetLinkPlacementX(m)i(r1).r4? c'
- System::Call 'OCSetupHlp::OCGetLinkPlacementY(m)i(r1).r5? c'
-!else
- System::Call 'OCSetupHlp::OCGetLinkPlacementX(t)i(r1).r4? c'
- System::Call 'OCSetupHlp::OCGetLinkPlacementY(t)i(r1).r5? c'
-!endif
- ; And create the link
-
- ${If} $4 != -1
- ${AndIf} $5 != -1
- ${NSD_CreateLink} $4 $5 $3 12u $2
- ${Else}
- ; Default positionning
- ${NSD_CreateLink} 54% 176 $3 12u $2
- ${EndIf}
- Pop $OCTOULabel
- ${NSD_OnClick} $OCTOULabel OCTOULabelClick
- ${EndIf}
-
- Pop $7
- Pop $6
- Pop $5
- Pop $4
- Pop $3
- Pop $2
- Pop $1
-
- System::Call 'OCSetupHlp::OCNSISAdjust(i, i, i, i, i)i($OCDialog, 14,70, 470, 228).r0? c'
- System::Call 'OCSetupHlp::OCRunDialog(i, i, i, i)i($OCDialog, 240, 240 ,240).r0? c'
-
- nsDialogs::Show
-
+ !insertmacro MUI_HEADER_TEXT $1 $2
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237NSISAdjust(i, i, i, i, i)i(r3, 14, 70, 470, 228).r0? c"
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237RunDialog(i)i(r3).r0? c"
+ ${If} $0 != ${OC_OFFER_RUNDIALOG_FAILURE}
+ StrCpy $OCAttached ${OC_NSIS_TRUE}
+ nsDialogs::Show
+ ${EndIf}
${EndIf}
+ Pop $3
+ Pop $2
+ Pop $1
+ ${Else}
+ ; No offer was not ready to be shown when the user reached the offer page
+ StrCpy $OCUseOfferPage ${OC_NSIS_FALSE}
+ ${EndIf}
- ${EndIf}
- Pop $0
- ${EndIf}
-FunctionEnd
-
-Function OCPPLabelClick
-
- Push $0
- Push $1
- StrCpy $1 "PP"
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCDisplay(m)i(r1).r0? c'
-!else
- System::Call 'OCSetupHlp::OCDisplay(t)i(r1).r0? c'
-!endif
- Pop $1
- Pop $0
+ Pop $0
+${Else}
+ StrCpy $OCUseOfferPage ${OC_NSIS_FALSE}
+ Abort
+${EndIf}
FunctionEnd
-Function OCTOULabelClick
- Push $0
- Push $1
- StrCpy $1 "TOU"
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCDisplay(m)i(r1).r0? c'
-!else
- System::Call 'OCSetupHlp::OCDisplay(t)i(r1).r0? c'
-!endif
- Pop $1
- Pop $0
-
-FunctionEnd
;
-; OpenCandyPageLeaveFn
-; --------------------
+; _OpenCandyPageLeaveFn
+; ---------------------
+; Decides if it is ok for the end user to leave the offer
+; page and continue with setup.
;
-; Decides there if it is ok to leave the
-; page and continues with setup
+; Do not call this function directly, it is a callback used
+; by the PageEx that is added to your .nsi script.
;
-; You do not need to call this function, it just
-; needs to be a parameter to the custom page
-; declared in your setup along with your other pages
+; Usage:
+;
+; # Insert the OpenCandy offer page
+; !insertmacro OpenCandyOfferPage
;
-Function OpenCandyPageLeaveFn
- ${If} $OCOSSupported == 0
- Push $0
+Function _OpenCandyPageLeaveFn
Push $0
- Push $1
- Push $2
- System::Call 'OCSetupHlp::OCGetOfferState()i.r0? c'
- ${If} $0 < 0
- StrCpy $1 "PleaseChoose"
- StrCpy $2 " "
-
-!ifdef NSIS_UNICODE
-
- Push $4
-
- System::Alloc /NOUNLOAD 1024
- Pop $4
-
- System::Call /NOUNLOAD 'OCSetupHlp::OCGetMsg(m,i)i(r1, r4).r0? c'
- System::Call /NOUNLOAD 'kernel32::MultiByteToWideChar(i 65001, i 0, i r4, i -1, t .r2, i 1024) i .r0'
-
- System::Free $4
-
- Pop $4
-
-!else
- System::Call 'OCSetupHlp::OCGetMsg(t,t)i(r1,.r2).r0? c'
-
- ; Convert from utf8 to display
- Push $2
- Push "65001"
- Push $LANGUAGE
- Call ConvertMultiByte
- Pop $2
-!endif
-
- MessageBox MB_ICONINFORMATION $2
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237CanLeaveOfferPage()i.r0? c"
+ ${If} $0 == ${OC_OFFER_LEAVEPAGE_DISALLOWED} ; If user must choose an option before proceeding
+ Pop $0
Abort
- ${Else}
- System::Call 'OCSetupHlp::OCDetach()i.r0? c'
- IntOp $OCDetached 0 + 1
${EndIf}
- Pop $2
- Pop $1
+ ${If} $OCAttached == ${OC_NSIS_TRUE}
+ System::Call "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237Detach()i.r0? c"
+ StrCpy $OCAttached ${OC_NSIS_FALSE}
+ ${EndIf}
Pop $0
- ${EndIf}
FunctionEnd
+
+
;
-; OpenCandyOnInstSuccess
-; ----------------------
+; _OpenCandyExecOfferInternal
+; ---------------------------
+; This macro is internal to this helper script. Do not
+; insert it in your own code. Instead see OpenCandyOnInstSuccess
+; and OpenCandyInstallEmbedded.
;
-; This macro needs to be called from the
-; NSIS function .onInstSuccess to signal
-; a successful installation of the product
-; and launch installation of the recommended
-; software if any was selected by the user
+; Parameters:
;
-
-!macro OpenCandyOnInstSuccess
-${If} $OCInitcode != -99
- ${If} $OCOSSupported == 0
-
- ${If} $OCNoCandy == 0
-
- ${If} $OCRemnant == 0
-
- Push $0
- Push $1
- Push $2
-
- StrCpy $2 " "
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCGetOfferType(m)i(.r2).r0? c'
-!else
- System::Call 'OCSetupHlp::OCGetOfferType(t)i(.r2).r0? c'
-!endif
- ; Check if we are in normal
- ; or embedded mode and run accordingy
-
- ${If} $0 == 1 ; OC_OFFER_TYPE_NORMAL
- GetFullPathName /SHORT $1 $INSTDIR\OpenCandy\OCSetupHlp.dll
- StrCpy $0 "$1,_MgrCheck@16"
-
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCExecuteOffer(m)i(r0).r1? c'
-!else
- System::Call 'OCSetupHlp::OCExecuteOffer(t)i(r0).r1? c'
-!endif
-
- ; Check if the offer was accepted
-
- Push $3
- System::Call 'OCSetupHlp::OCGetOfferState()i.r3? c'
-
- ${If} $3 == 1 ; Offer was accepted
-
- GetFullPathName /SHORT $1 $INSTDIR\OpenCandy\OCSetupHlp.dll
- StrCpy $0 "RunDll32.exe $1,_MgrCheck@16 $2"
- Exec $0
-
- ${EndIf}
-
- Pop $3
-
- ${EndIf}
-
- Pop $2
- Pop $1
- Pop $0
-
- System::Call 'OCSetupHlp::OCSignalProductInstalled()i.r0? c'
-
- ${EndIf}
- ${EndIf}
- ${EndIf}
-${EndIF}
-!macroend
-
-
+; OC_OFFER_TYPE : The offer type, OC_OFFER_TYPE_NORMAL or OC_OFFER_TYPE_EMBEDDED
;
-; OpenCandyOnInstFailed
-; ----------------------
+; Usage:
;
-; This macro needs to be called from the
-; NSIS function .onInstFailed to signal
-; a failed installation of the product.
+; # DO NOT USE _OpenCandyExecOfferInternal directly!
+; !insertmacro _OpenCandyExecOfferInternal ${OC_OFFER_TYPE_NORMAL}
;
-!macro OpenCandyOnInstFailed
- ${If} $OCInitcode != -99
- ${If} $OCOSSupported == 0
- ${If} $OCNoCandy == 0
-
- Push $0
- System::Call 'OCSetupHlp::OCSignalProductFailed()i.r0? c'
- Pop $0
-
+!macro _OpenCandyExecOfferInternal OC_OFFER_TYPE
+!if "${OC_OFFER_TYPE}" != "${OC_OFFER_TYPE_NORMAL}"
+ !if "${OC_OFFER_TYPE}" != "${OC_OFFER_TYPE_EMBEDDED}"
+ !error "Unsupported offer type '${OC_OFFER_TYPE}' in _OpenCandyExecOfferInternal"
+ !endif
+!endif
+ Push $0
+ ${If} $OCUseOfferPage == ${OC_NSIS_TRUE}
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237GetOfferType() i.r0? c"
+ ${If} $0 == ${OC_OFFER_TYPE}
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237PrepareDownload()i().r0? c"
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237GetOfferState()i().r0? c"
+ ${If} $0 == ${OC_OFFER_CHOICE_ACCEPTED}
+ System::Call /NOUNLOAD "$PLUGINSDIR\OCSetupHlp.dll::OCPRD237StartDLMgr2Download()? c"
${EndIf}
${EndIf}
- ${EndIF}
+ ${EndIf}
+ Pop $0
!macroend
-
-;
-; OpenCandyOnGuiEnd
-; -----------------
;
-; This needs to be called from the NSIS
-; function .onGUIEnd to properly unload
-; the OpenCandy DLL. We need to have the DLL
-; loaded until then as to be able to start
-; the recommended software setup at the
-; very end of the NSIS install process
+; OpenCandyOnInstSuccess
+; ----------------------
;
-
-!macro OpenCandyOnGuiEnd
-
- ${If} $OCOSSupported == 0
-
- ${If} $OCUseOfferPage != 0
-
- ${If} $OCRemnant == 0
-
- Push $0
- Push $1
-
- StrCpy $1 " "
-
-!ifdef NSIS_UNICODE
- System::Call 'OCSetupHlp::OCGetOfferType(m)i(.r1).r0? c'
-!else
- System::Call 'OCSetupHlp::OCGetOfferType(t)i(.r1).r0? c'
-!endif
-
- ; Check if we are in normal
- ; or embedded mode and run accordingy
-
- ${If} $0 == 2 ; OC_OFFER_TYPE_EMBEDDED
-
- ; We need to delete the OpenCandy folder
- RMDir /REBOOTOK "$INSTDIR\OpenCandy"
-
- ${EndIf}
-
- ${If} $OCDetached == 0
- System::Call 'OCSetupHlp::OCDetach()i.r0? c'
- IntOp $OCDetached 0 + 1
- ${EndIf}
-
- ; Always call shutdown to cleanup
- System::Call 'OCSetupHlp::OCShutdown()i.r0? c'
-
- IntOp $OCUseOfferPage 0 + 0
-
- ${EndIf}
-
- ${EndIf}
-
- ; In all cases, let's unload the DLL
- ; by calling the system plugin with "u"
- System::Call 'OCSetupHlp::OCDetach()i.r0? u'
-
- ; And clean up after ourselves
- SetPluginUnload manual
- ; do nothing (but let the installer unload the System dll)
- System::Free 0
-
- ${EndIf}
-
-!macroend
-
+; This macro needs to be inserted in the .onInstSuccess callback function
+; to sig...
[truncated message content] |
|
From: Shakesoda <de...@st...> - 2011-02-26 02:21:18
|
Modified: branches/4.0/stepmania/Themes/instructions.txt Log: Fix typo Modified: branches/4.0/stepmania/Themes/instructions.txt ============================================================================== --- branches/4.0/stepmania/Themes/instructions.txt (original) +++ branches/4.0/stepmania/Themes/instructions.txt Fri Feb 25 18:21:11 2011 @@ -1 +1 @@ -Place Theme folders here. More more information on the theme format, see the readme file. \ No newline at end of file +Place Theme folders here. For more information on the theme format, see the readme file. \ No newline at end of file |
|
From: Shakesoda <de...@st...> - 2011-02-26 01:47:12
|
Added:
branches/4.0/stepmania/src/StepMania-net2008.sln
Modified:
branches/4.0/stepmania/src/StepMania-net2005.vcproj
Log:
Add VC 2008 project. Doesn't build at the moment (linker error, something is missing from Preference.cpp it looks like).
Modified: branches/4.0/stepmania/src/StepMania-net2005.vcproj
==============================================================================
--- branches/4.0/stepmania/src/StepMania-net2005.vcproj (original)
+++ branches/4.0/stepmania/src/StepMania-net2005.vcproj Fri Feb 25 17:46:57 2011
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="8.00"
- Name="StepMania-net2005"
+ Version="9.00"
+ Name="StepMania-net2008"
ProjectGUID="{AF209DBD-24BD-4356-8DFE-41751B221195}"
RootNamespace="StepMania"
Keyword="MFCProj"
+ TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
@@ -92,6 +93,8 @@
MapFileName="$(IntDir)\$(TargetName).map"
MapExports="true"
SubSystem="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
@@ -112,9 +115,6 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
CommandLine="archutils\Win32\mapconv "$(IntDir)\$(TargetName).map" "$(TargetDir)\StepMania.vdi""
/>
@@ -157,7 +157,7 @@
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="2"
- AdditionalIncludeDirectories=".;vorbis;libjpeg;"lua-5.0\include";"ffmpeg\include""
+ AdditionalIncludeDirectories=".;vorbis;libjpeg;"lua-5.0\include";ffmpeg\include;jsoncpp\include"
PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS,WINDOWS,RELEASE"
StringPooling="true"
MinimalRebuild="false"
@@ -200,6 +200,8 @@
MapFileName="$(IntDir)\$(TargetName).map"
MapExports="true"
SubSystem="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
@@ -220,9 +222,6 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
CommandLine="archutils\Win32\mapconv "$(IntDir)\$(TargetName).map" "$(TargetDir)\StepMania.vdi""
/>
@@ -302,6 +301,8 @@
MapFileName="$(IntDir)\$(TargetName).map"
MapExports="true"
SubSystem="2"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
@@ -322,9 +323,6 @@
Name="VCAppVerifierTool"
/>
<Tool
- Name="VCWebDeploymentTool"
- />
- <Tool
Name="VCPostBuildEventTool"
CommandLine="archutils\Win32\mapconv "$(IntDir)\$(TargetName).map" "$(TargetDir)\StepMania.vdi""
/>
@@ -361,14 +359,6 @@
>
</File>
<File
- RelativePath="ScreenCenterImage.cpp"
- >
- </File>
- <File
- RelativePath="ScreenCenterImage.h"
- >
- </File>
- <File
RelativePath="ScreenCredits.cpp"
>
</File>
@@ -1073,6 +1063,14 @@
>
</File>
<File
+ RelativePath=".\CreateZip.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CreateZip.h"
+ >
+ </File>
+ <File
RelativePath="DateTime.cpp"
>
</File>
@@ -1097,6 +1095,14 @@
>
</File>
<File
+ RelativePath=".\ExportPackage.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\ExportPackage.h"
+ >
+ </File>
+ <File
RelativePath=".\Font.cpp"
>
</File>
@@ -1185,6 +1191,14 @@
>
</File>
<File
+ RelativePath=".\JsonUtil.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\JsonUtil.h"
+ >
+ </File>
+ <File
RelativePath=".\LocalizedString.cpp"
>
</File>
@@ -1293,6 +1307,14 @@
>
</File>
<File
+ RelativePath=".\NotesLoaderJson.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\NotesLoaderJson.h"
+ >
+ </File>
+ <File
RelativePath="NotesLoaderKSF.cpp"
>
</File>
@@ -1317,6 +1339,14 @@
>
</File>
<File
+ RelativePath=".\NotesWriterJson.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\NotesWriterJson.h"
+ >
+ </File>
+ <File
RelativePath="NotesWriterSM.cpp"
>
</File>
@@ -1617,6 +1647,22 @@
Name="StepMania"
>
<File
+ RelativePath=".\CommandLineActions.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CommandLineActions.h"
+ >
+ </File>
+ <File
+ RelativePath=".\FileDownload.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\FileDownload.h"
+ >
+ </File>
+ <File
RelativePath=".\GameLoop.cpp"
>
</File>
@@ -3261,6 +3307,10 @@
>
</File>
<File
+ RelativePath=".\RageTypes.cpp"
+ >
+ </File>
+ <File
RelativePath="RageTypes.h"
>
</File>
@@ -3517,14 +3567,6 @@
>
</File>
<File
- RelativePath=".\ExportNsisStrings.cpp"
- >
- </File>
- <File
- RelativePath=".\ExportNsisStrings.h"
- >
- </File>
- <File
RelativePath="ezsockets.cpp"
>
</File>
@@ -4226,6 +4268,34 @@
>
</File>
<File
+ RelativePath=".\jsoncpp\src\lib_json\json_batchallocator.h"
+ >
+ </File>
+ <File
+ RelativePath=".\jsoncpp\src\lib_json\json_internalarray.inl"
+ >
+ </File>
+ <File
+ RelativePath=".\jsoncpp\src\lib_json\json_internalmap.inl"
+ >
+ </File>
+ <File
+ RelativePath=".\jsoncpp\src\lib_json\json_reader.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\jsoncpp\src\lib_json\json_value.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\jsoncpp\src\lib_json\json_valueiterator.inl"
+ >
+ </File>
+ <File
+ RelativePath=".\jsoncpp\src\lib_json\json_writer.cpp"
+ >
+ </File>
+ <File
RelativePath="StepMania.xpm"
>
</File>
Added: branches/4.0/stepmania/src/StepMania-net2008.sln
==============================================================================
--- (empty file)
+++ branches/4.0/stepmania/src/StepMania-net2008.sln Fri Feb 25 17:46:57 2011
@@ -0,0 +1,23 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual C++ Express 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StepMania-net2005", "StepMania-net2005.vcproj", "{AF209DBD-24BD-4356-8DFE-41751B221195}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ FastDebug|Win32 = FastDebug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {AF209DBD-24BD-4356-8DFE-41751B221195}.Debug|Win32.ActiveCfg = Debug|Win32
+ {AF209DBD-24BD-4356-8DFE-41751B221195}.Debug|Win32.Build.0 = Debug|Win32
+ {AF209DBD-24BD-4356-8DFE-41751B221195}.FastDebug|Win32.ActiveCfg = FastDebug|Win32
+ {AF209DBD-24BD-4356-8DFE-41751B221195}.FastDebug|Win32.Build.0 = FastDebug|Win32
+ {AF209DBD-24BD-4356-8DFE-41751B221195}.Release|Win32.ActiveCfg = Release|Win32
+ {AF209DBD-24BD-4356-8DFE-41751B221195}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
|
|
From: Chris D. <de...@st...> - 2011-02-25 01:15:07
|
Modified:
branches/4.0/stepmania/src/NotesLoaderJson.cpp
branches/4.0/stepmania/src/NotesWriterJson.cpp
branches/4.0/stepmania/src/NotesWriterJson.h
branches/4.0/stepmania/src/ScreenDebugOverlay.cpp
branches/4.0/stepmania/src/Song.cpp
branches/4.0/stepmania/src/Steps.cpp
branches/4.0/stepmania/src/Steps.h
branches/4.0/stepmania/src/song.h
Log:
add Export to Json debug menu action
Modified: branches/4.0/stepmania/src/NotesLoaderJson.cpp
==============================================================================
--- branches/4.0/stepmania/src/NotesLoaderJson.cpp (original)
+++ branches/4.0/stepmania/src/NotesLoaderJson.cpp Thu Feb 24 16:56:05 2011
@@ -17,20 +17,20 @@ void NotesLoaderJson::GetApplicableFiles
void Deserialize(BPMSegment &seg, const Json::Value &root)
{
- seg.m_iStartIndex = root["StartIndex"].asInt();
- seg.m_fBPS = (float)root["BPS"].asDouble();
+ seg.m_iStartIndex = BeatToNoteRow((float)root["Beat"].asDouble());
+ seg.m_fBPS = (float)(root["BPM"].asDouble() / 60);
}
static void Deserialize(StopSegment &seg, const Json::Value &root)
{
- seg.m_iStartRow = root["StartRow"].asInt();
- seg.m_fStopSeconds = (float)root["StopSeconds"].asDouble();
+ seg.m_iStartRow = BeatToNoteRow((float)(root["Beat"].asDouble()));
+ seg.m_fStopSeconds = (float)root["Seconds"].asDouble();
}
static void Deserialize(TimingData &td, const Json::Value &root)
{
- JsonUtil::DeserializeVectorObjects( td.m_BPMSegments, Deserialize, root["BPMs"] );
- JsonUtil::DeserializeVectorObjects( td.m_StopSegments, Deserialize, root["Stops"] );
+ JsonUtil::DeserializeVectorObjects( td.m_BPMSegments, Deserialize, root["BpmSegments"] );
+ JsonUtil::DeserializeVectorObjects( td.m_StopSegments, Deserialize, root["StopSegments"] );
}
static void Deserialize(LyricSegment &o, const Json::Value &root)
@@ -76,22 +76,20 @@ static void Deserialize( TapNote &o, con
o.pn = (PlayerNumber)root["PlayerNumber"].asInt();
}
-static void Deserialize( NoteData &o, const Json::Value &root )
+static void Deserialize( StepsType st, NoteData &nd, const Json::Value &root )
{
- o.SetNumTracks(root.size());
- for( unsigned t=0; t<root.size(); t++ )
- {
- NoteData::TrackMap tm = o.GetTrack(t);
- const Json::Value &root2 = root[t];
- Json::Value::Members m = root2.getMemberNames();
- FOREACH_CONST( string, m, key )
- {
- int row = atoi( key->c_str() );
- const Json::Value &root3 = root2[*key];
- TapNote tn;
- Deserialize( tn, root3 );
- o.SetTapNote( t, row, tn );
- }
+ int iTracks = GAMEMAN->StepsTypeToNumTracks( st );
+ nd.SetNumTracks( iTracks );
+ for( unsigned i=0; i<root.size(); i++ )
+ {
+ Json::Value root2 = root[i];
+ float fBeat = (float)root2[(unsigned)0].asDouble();
+ int iRow = BeatToNoteRow(fBeat);
+ int iTrack = root2[1].asInt();
+ const Json::Value &root3 = root2[2];
+ TapNote tn;
+ Deserialize( tn, root3 );
+ nd.SetTapNote( iTrack, iRow, tn );
}
}
@@ -110,7 +108,7 @@ static void Deserialize( Steps &o, const
o.Decompress();
NoteData nd;
- Deserialize( nd, root["NoteData"] );
+ Deserialize( o.m_StepsType, nd, root["NoteData"] );
o.SetNoteData( nd );
//o.SetHash( root["Hash"].asInt() );
o.SetDescription( root["Description"].asString() );
@@ -179,7 +177,7 @@ static void Deserialize( Song &out, cons
{
vector<Steps*> vpSteps;
- JsonUtil::DeserializeVectorPointers<Steps>( vpSteps, Deserialize, root["Steps"] );
+ JsonUtil::DeserializeVectorPointers<Steps>( vpSteps, Deserialize, root["Charts"] );
FOREACH( Steps*, vpSteps, iter )
out.AddSteps( *iter );
}
Modified: branches/4.0/stepmania/src/NotesWriterJson.cpp
==============================================================================
--- branches/4.0/stepmania/src/NotesWriterJson.cpp (original)
+++ branches/4.0/stepmania/src/NotesWriterJson.cpp Thu Feb 24 16:56:05 2011
@@ -11,20 +11,20 @@
void Serialize(const BPMSegment &seg, Json::Value &root)
{
- root["StartIndex"] = seg.m_iStartIndex;
- root["BPS"] = seg.m_fBPS;
+ root["Beat"] = NoteRowToBeat(seg.m_iStartIndex);
+ root["BPM"] = seg.m_fBPS * 60;
}
static void Serialize(const StopSegment &seg, Json::Value &root)
{
- root["StartRow"] = seg.m_iStartRow;
- root["StopSeconds"] = seg.m_fStopSeconds;
+ root["Beat"] = NoteRowToBeat(seg.m_iStartRow);
+ root["Seconds"] = seg.m_fStopSeconds;
}
static void Serialize(const TimingData &td, Json::Value &root)
{
- JsonUtil::SerializeVectorObjects( td.m_BPMSegments, Serialize, root["BPMs"] );
- JsonUtil::SerializeVectorObjects( td.m_StopSegments, Serialize, root["Stops"] );
+ JsonUtil::SerializeVectorObjects( td.m_BPMSegments, Serialize, root["BpmSegments"] );
+ JsonUtil::SerializeVectorObjects( td.m_StopSegments, Serialize, root["StopSegments"] );
}
static void Serialize(const LyricSegment &o, Json::Value &root)
@@ -75,18 +75,20 @@ static void Serialize( const NoteData &o
{
root = Json::Value(Json::arrayValue);
int iNumTracks = o.GetNumTracks();
- root.resize( iNumTracks );
for(int t=0; t<iNumTracks; t++ )
{
NoteData::TrackMap tm = o.GetTrack(t);
- Json::Value &root2 = root[t];
FOREACHM_CONST( int, TapNote, tm, iter )
{
- int row = iter->first;
+ int iRow = iter->first;
TapNote tn = iter->second;
- RString sKey = ssprintf("%d",row);
- Json::Value &root3 = root2[sKey];
- Serialize( tn, root3 );
+ root.resize( root.size()+1 );
+ Json::Value &root2 = root[ root.size()-1 ];
+ root2 = Json::Value(Json::arrayValue);
+ root2.resize(3);
+ root2[(unsigned)0] = NoteRowToBeat(iRow);
+ root2[1] = t;
+ Serialize( tn, root2[2] );
}
}
}
@@ -116,7 +118,7 @@ static void Serialize( const Steps &o, J
}
-bool NotesWriterJson::Write( RString sFile, const Song &out, bool bSavingCache )
+bool NotesWriterJson::WriteSong( const RString &sFile, const Song &out, bool bWriteSteps )
{
Json::Value root;
root["SongDir"] = out.m_sSongDir;
@@ -172,6 +174,7 @@ bool NotesWriterJson::Write( RString sFi
JsonUtil::SerializeArrayValues( out.m_vsKeysoundFile, root["KeySounds"] );
+ if( bWriteSteps )
{
vector<const Steps*> vpSteps;
FOREACH_CONST( Steps*, out.GetAllSteps(), iter )
@@ -180,11 +183,17 @@ bool NotesWriterJson::Write( RString sFi
continue;
vpSteps.push_back( *iter );
}
- JsonUtil::SerializeVectorPointers<Steps>( vpSteps, Serialize, root["Steps"] );
+ JsonUtil::SerializeVectorPointers<Steps>( vpSteps, Serialize, root["Charts"] );
}
- bool bMinified = bSavingCache;
- return JsonUtil::WriteFile( root, sFile, bMinified );
+ return JsonUtil::WriteFile( root, sFile, false );
+}
+
+bool NotesWriterJson::WriteSteps( const RString &sFile, const Steps &out )
+{
+ Json::Value root;
+ Serialize( out, root );
+ return JsonUtil::WriteFile( root, sFile, false );
}
/*
Modified: branches/4.0/stepmania/src/NotesWriterJson.h
==============================================================================
--- branches/4.0/stepmania/src/NotesWriterJson.h (original)
+++ branches/4.0/stepmania/src/NotesWriterJson.h Thu Feb 24 16:56:05 2011
@@ -4,11 +4,13 @@
#define NotesWriterJson_H
class Song;
+class Steps;
class NotesWriterJson
{
public:
- static bool Write( RString sPath, const Song &out, bool bSavingCache );
+ static bool WriteSong( const RString &sFile, const Song &out, bool bWriteSteps );
+ static bool WriteSteps( const RString &sFile, const Steps &out );
};
#endif
Modified: branches/4.0/stepmania/src/ScreenDebugOverlay.cpp
==============================================================================
--- branches/4.0/stepmania/src/ScreenDebugOverlay.cpp (original)
+++ branches/4.0/stepmania/src/ScreenDebugOverlay.cpp Thu Feb 24 16:56:05 2011
@@ -25,6 +25,11 @@
#include "SongManager.h"
#include "GameLoop.h"
#include "ScreenServiceAction.h"
+#include "RageFileManager.h"
+#include "NotesWriterJson.h"
+#include "Steps.h"
+#include "RageSurfaceUtils.h"
+#include "RageSurface_Load.h"
static bool g_bIsDisplayed = false;
static bool g_bIsSlow = false;
@@ -802,6 +807,75 @@ class DebugLineWriteProfiles : public ID
}
};
+class DebugLineWriteJson : public IDebugLine
+{
+ virtual RString GetDescription() { return "Write Song JSON"; }
+ virtual RString GetValue() { return RString(); }
+ virtual bool IsEnabled() { return true; }
+ virtual void Do( RString &sMessageOut )
+ {
+ int iSongId = 1;
+ int iStepsId = 1;
+
+ FILEMAN->CreateDir("/JsonSongs/");
+ const vector<Song*> &songs = SONGMAN->GetAllSongs();
+ FOREACH_CONST( Song*, songs, pSong )
+ {
+ RString sSongDir = ssprintf( "/JsonSongs/%d/", iSongId++ );
+ RString sSongFile = sSongDir + "/song.json";
+ RString sStepsDir = sSongDir + "/steps/";
+ FILEMAN->CreateDir(sStepsDir);
+
+ NotesWriterJson::WriteSong( sSongFile, **pSong, false );
+ const vector<Steps*> &vpSteps = (*pSong)->GetAllSteps();
+
+ FOREACH_CONST( Steps*, vpSteps, pSteps )
+ {
+ if( (*pSteps)->IsAutogen() )
+ continue;
+ RString sStepsFile = sStepsDir + ssprintf( "%d.json", iStepsId++ );
+ NotesWriterJson::WriteSteps( sStepsFile, **pSteps );
+
+ {
+ RString sSrcFile = (*pSong)->GetBackgroundPath();
+ RString sDstFile = sSongDir + "background.png";
+ if( GetExtension(sSrcFile) == "png" )
+ {
+ FileCopy( sSrcFile, sDstFile );
+ }
+ else
+ {
+ RString error;
+ RageSurface *img = RageSurfaceUtils::LoadFile( sSrcFile, error );
+ RageSurfaceUtils::SaveSurface( img, sDstFile );
+ }
+ }
+
+ {
+ RString sSrcFile = (*pSong)->GetBannerPath();
+ RString sDstFile = sSongDir + "banner.png";
+ if( GetExtension(sSrcFile) == "png" )
+ {
+ FileCopy( sSrcFile, sDstFile );
+ }
+ else
+ {
+ RString error;
+ RageSurface *img = RageSurfaceUtils::LoadFile( sSrcFile, error );
+ RageSurfaceUtils::SaveSurface( img, sDstFile );
+ }
+ }
+
+ {
+ RString sSrcFile = (*pSong)->GetMusicPath();
+ RString sDstFile = sSongDir + "music." + GetExtension(sSrcFile);
+ FileCopy( sSrcFile, sDstFile );
+ }
+ }
+ }
+ }
+};
+
class DebugLineWritePreferences : public IDebugLine
{
virtual RString GetDescription() { return WRITE_PREFERENCES.GetValue(); }
@@ -916,6 +990,7 @@ DECLARE_ONE( DebugLineFillMachineStats )
DECLARE_ONE( DebugLineSendNotesEnded );
DECLARE_ONE( DebugLineReloadCurrentScreen );
DECLARE_ONE( DebugLineReloadTheme );
+DECLARE_ONE( DebugLineWriteJson );
DECLARE_ONE( DebugLineWriteProfiles );
DECLARE_ONE( DebugLineWritePreferences );
DECLARE_ONE( DebugLineMenuTimer );
Modified: branches/4.0/stepmania/src/Song.cpp
==============================================================================
--- branches/4.0/stepmania/src/Song.cpp (original)
+++ branches/4.0/stepmania/src/Song.cpp Thu Feb 24 16:56:05 2011
@@ -59,10 +59,11 @@ StringToX( DisplayBpmType );
Song::Song()
{
+ m_iStepManiaSongId = -1;
+
FOREACH_BackgroundLayer( i )
m_BackgroundChanges[i] = AutoPtrCopyOnWrite<VBackgroundChange>(new VBackgroundChange);
m_ForegroundChanges = AutoPtrCopyOnWrite<VBackgroundChange>(new VBackgroundChange);
-
m_LoadedFromProfile = ProfileSlot_INVALID;
m_fMusicSampleStartSeconds = -1;
@@ -778,15 +779,11 @@ bool Song::SaveToSMFile( RString sPath,
return wr.Write(sPath, *this, bSavingCache);
}
-bool Song::SaveToJsonFile( RString sPath, bool bSavingCache )
+bool Song::SaveToJsonFile( RString sPath)
{
LOG->Trace( "Song::SaveToJsonFile('%s')", sPath.c_str() );
- /* If the file exists, make a backup. */
- if( !bSavingCache && IsAFile(sPath) )
- FileCopy( sPath, sPath + ".old" );
-
- return NotesWriterJson::Write(sPath, *this, bSavingCache);
+ return NotesWriterJson::WriteSong(sPath, *this, true);
}
void Song::SaveToCacheFile()
Modified: branches/4.0/stepmania/src/Steps.cpp
==============================================================================
--- branches/4.0/stepmania/src/Steps.cpp (original)
+++ branches/4.0/stepmania/src/Steps.cpp Thu Feb 24 16:56:05 2011
@@ -27,6 +27,8 @@
Steps::Steps()
{
+ m_iStepManiaStepsId = -1;
+
m_bSavedToDisk = false;
m_StepsType = STEPS_TYPE_INVALID;
m_LoadedFromProfile = ProfileSlot_INVALID;
Modified: branches/4.0/stepmania/src/Steps.h
==============================================================================
--- branches/4.0/stepmania/src/Steps.h (original)
+++ branches/4.0/stepmania/src/Steps.h Thu Feb 24 16:56:05 2011
@@ -21,6 +21,8 @@ public:
Steps();
~Steps();
+ int m_iStepManiaStepsId;
+
// initializers
void AutogenFrom( const Steps *parent, StepsType ntTo );
void CopyFrom( Steps* pSource, StepsType ntTo, float fMusicLengthSeconds );
Modified: branches/4.0/stepmania/src/song.h
==============================================================================
--- branches/4.0/stepmania/src/song.h (original)
+++ branches/4.0/stepmania/src/song.h Thu Feb 24 16:56:05 2011
@@ -68,6 +68,7 @@ class Song
{
public:
RString m_sSongDir;
+ int m_iStepManiaSongId;
ShowSong m_SelectionDisplay;
@@ -83,7 +84,7 @@ public:
void TranslateTitles(); // called by TidyUpData
bool Save(); // saves SM and DWI
- bool SaveToJsonFile( RString sPath, bool bSavingCache );
+ bool SaveToJsonFile( RString sPath );
bool SaveToSMFile( RString sPath, bool bSavingCache );
void SaveToCacheFile();
void SaveToDWIFile();
|
|
From: Chris D. <de...@st...> - 2011-01-16 09:15:10
|
Modified:
branches/4.0/stepmania/src/GameState.cpp
branches/4.0/stepmania/src/JsonUtil.cpp
branches/4.0/stepmania/src/JsonUtil.h
branches/4.0/stepmania/src/Profile.cpp
branches/4.0/stepmania/src/Profile.h
branches/4.0/stepmania/src/ProfileManager.cpp
branches/4.0/stepmania/src/ProfileManager.h
Log:
Upload stats every time we write stats.json.gz. Currently synchronous, but that will change.
Modified: branches/4.0/stepmania/src/GameState.cpp
==============================================================================
--- branches/4.0/stepmania/src/GameState.cpp (original)
+++ branches/4.0/stepmania/src/GameState.cpp Sun Jan 16 01:15:02 2011
@@ -383,6 +383,26 @@ void GameState::PlayersFinalized()
ApplyModifiers( pn, CommonMetrics::DEFAULT_CPU_MODIFIERS );
}
+void SaveAllProfiles( bool bEndGame )
+{
+ PROFILEMAN->SaveMachineProfile();
+ PROFILEMAN->UploadMachineProfie();
+ FOREACH_HumanPlayer( pn )
+ {
+ if( !PROFILEMAN->IsPersistentProfile(pn) )
+ continue;
+
+ bool bWasMemoryCard = PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn);
+ if( bEndGame && bWasMemoryCard )
+ MEMCARDMAN->MountCard( pn );
+ PROFILEMAN->SaveProfile( pn );
+ if( bEndGame && bWasMemoryCard )
+ MEMCARDMAN->UnmountCard( pn );
+
+ PROFILEMAN->UnloadProfile( pn );
+ }
+}
+
void GameState::EndGame()
{
LOG->Trace( "GameState::EndGame" );
@@ -415,22 +435,7 @@ void GameState::EndGame()
BOOKKEEPER->WriteToDisk();
- FOREACH_HumanPlayer( pn )
- {
- if( !PROFILEMAN->IsPersistentProfile(pn) )
- continue;
-
- bool bWasMemoryCard = PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn);
- if( bWasMemoryCard )
- MEMCARDMAN->MountCard( pn );
- PROFILEMAN->SaveProfile( pn );
- if( bWasMemoryCard )
- MEMCARDMAN->UnmountCard( pn );
-
- PROFILEMAN->UnloadProfile( pn );
- }
-
- PROFILEMAN->SaveMachineProfile();
+ SaveAllProfiles( true );
// make sure we don't execute EndGame twice.
m_timeGameStarted.SetZero();
@@ -534,7 +539,7 @@ void GameState::FinishStage()
if( iOldStageIndex/iSaveProfileEvery < m_iCurrentStageIndex/iSaveProfileEvery )
{
LOG->Trace( "Played %i stages; saving profiles ...", iSaveProfileEvery );
- PROFILEMAN->SaveAllProfiles();
+ SaveAllProfiles(false);
}
}
}
Modified: branches/4.0/stepmania/src/JsonUtil.cpp
==============================================================================
--- branches/4.0/stepmania/src/JsonUtil.cpp (original)
+++ branches/4.0/stepmania/src/JsonUtil.cpp Sun Jan 16 01:15:02 2011
@@ -63,20 +63,25 @@ bool JsonUtil::WriteFile( const Json::Va
return WriteFile( root, f, bMinified );
}
-bool JsonUtil::WriteFile( const Json::Value &root, RageFileBasic &f, bool bMinified )
+RString JsonUtil::WriteString( const Json::Value &root, bool bMinified)
{
- std::string s;
if( !bMinified )
{
Json::StyledWriter writer;
- s = writer.write(root);
+ return writer.write(root);
}
else
{
Json::FastWriter writer;
- s = writer.write(root);
+ return writer.write(root);
}
+}
+
+bool JsonUtil::WriteFile( const Json::Value &root, RageFileBasic &f, bool bMinified )
+{
+ // Optimization Opportunity: Write to the file stream as we serialize
+ RString s = WriteString(root, bMinified);
f.Write(s);
return true;
}
Modified: branches/4.0/stepmania/src/JsonUtil.h
==============================================================================
--- branches/4.0/stepmania/src/JsonUtil.h (original)
+++ branches/4.0/stepmania/src/JsonUtil.h Sun Jan 16 01:15:02 2011
@@ -14,6 +14,7 @@ namespace JsonUtil
bool LoadFromFileShowErrors( Json::Value &root, const RString &sFile );
bool LoadFromFileShowErrors( Json::Value &root, RageFileBasic &f );
+ RString WriteString( const Json::Value &root, bool bMinified);
bool WriteFile( const Json::Value &root, const RString &sFile, bool bMinified );
bool WriteFile( const Json::Value &root, RageFileBasic &f, bool bMinified );
Modified: branches/4.0/stepmania/src/Profile.cpp
==============================================================================
--- branches/4.0/stepmania/src/Profile.cpp (original)
+++ branches/4.0/stepmania/src/Profile.cpp Sun Jan 16 01:15:02 2011
@@ -938,10 +938,67 @@ void Profile::RankingCategoryToHighScore
JsonUtil::DeserializeStringToObjectMap( m_v, StringToRankingCategory, root );
}
-bool Profile::SaveStatsJsonToDir( RString sDir, bool bSignData ) const
+const RString MeterToString(int i)
{
- Json::Value root;
- SaveGeneral( root["General"] );
+ return ssprintf("%d",i);
+}
+
+int StringToMeter(const RString &s)
+{
+ return atoi(s);
+}
+
+void Profile::SaveStatsJson( Json::Value &root ) const
+{
+ {
+ // These are write-only elements that are normally never read again.
+ // This data is required by other apps (like internet ranking), but is
+ // redundant to the game app.
+ root["DisplayName"] = GetDisplayNameOrHighScoreName();
+ root["CharacterID"] = m_sCharacterID;
+ root["LastUsedHighScoreName"] = m_sLastUsedHighScoreName;
+ root["WeightPounds"] = m_iWeightPounds;
+ root["IsMachine"] = IsMachine();
+ root["IsWeightSet"] = m_iWeightPounds != 0;
+
+ root["Guid"] = m_sGuid;
+ root["SortOrder"] = SortOrderToString(m_SortOrder);
+ root["LastDifficulty"] = DifficultyToString(m_LastDifficulty);
+ root["LastCourseDifficulty"] = CourseDifficultyToString(m_LastCourseDifficulty);
+ m_lastSong.Serialize( root["LastSong"] );
+ m_lastCourse.Serialize( root["LastCourse"] );
+ root["TotalPlays"] = m_iTotalPlays;
+ root["TotalPlaySeconds"] = m_iTotalPlaySeconds;
+ root["TotalGameplaySeconds"] = m_iTotalGameplaySeconds;
+ root["CurrentCombo"] = m_iCurrentCombo;
+ root["TotalCaloriesBurned"] = m_fTotalCaloriesBurned;
+ root["GoalType"] = m_GoalType;
+ root["GoalCalories"] = m_iGoalCalories;
+ root["GoalSeconds"] = m_iGoalSeconds;
+ root["LastPlayedMachineGuid"] = m_sLastPlayedMachineGuid;
+ root["LastPlayedDate"] = m_LastPlayedDate.GetString();
+ root["TotalDancePoints"] = m_iTotalDancePoints;
+ root["NumExtraStagesPassed"] = m_iNumExtraStagesPassed;
+ root["NumExtraStagesFailed"] = m_iNumExtraStagesFailed;
+ root["NumToasties"] = m_iNumToasties;
+ root["TotalTapsAndHolds"] = m_iTotalTapsAndHolds;
+ root["TotalJumps"] = m_iTotalJumps;
+ root["TotalHolds"] = m_iTotalHolds;
+ root["TotalRolls"] = m_iTotalRolls;
+ root["TotalMines"] = m_iTotalMines;
+ root["TotalHands"] = m_iTotalHands;
+ root["SavedLuaData"] = m_SavedLuaData.Serialize();
+ root["NumTotalSongsPlayed"] = m_iNumTotalSongsPlayed;
+
+ JsonUtil::SerializeValueToValueMap( m_DefaultModifiersByGame, root["DefaultModifiersByGame"] );
+ JsonUtil::SerializeArrayValues( m_UnlockedEntryIDs, root["UnlockEntryIDs"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByPlayMode, PlayModeToString, root["NumSongsPlayedByPlayMode"] );
+ JsonUtil::SerializeObjectToValueMapAsArray(m_iNumSongsPlayedByStyle, "Style", "NumPlays", root["NumSongsPlayedByStyle"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByDifficulty, DifficultyToString, root["NumSongsPlayedByDifficulty"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByMeter, MeterToString, root["NumSongsPlayedByMeter"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumStagesPassedByPlayMode, PlayModeToString, root["NumStagesPassedByPlayMode"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumStagesPassedByGrade, GradeToString, root["NumStagesPassedByGrade"] );
+ }
JsonUtil::SerializeObjectToObjectMapAsArray( m_SongHighScores, "Song", "HighScoresForASong", root["SongScores"] );
JsonUtil::SerializeObjectToObjectMapAsArray( m_CourseHighScores, "Course", "HighScoresForACourse", root["CourseScores"] );
JsonUtil::SerializeStringToObjectMap( m_CategoryHighScores, StepsTypeToString, root["CategoryScores"] );
@@ -949,6 +1006,12 @@ bool Profile::SaveStatsJsonToDir( RStrin
JsonUtil::SerializeStringToValueMap( m_mapDayToCaloriesBurned, DateTimeToString, root["CalorieData"] );
JsonUtil::SerializeArrayObjects( m_vRecentStepsScores, root["RecentSongScores"] );
JsonUtil::SerializeArrayObjects( m_vRecentCourseScores, root["RecentCourseScores"] );
+}
+
+bool Profile::SaveStatsJsonToDir( RString sDir, bool bSignData ) const
+{
+ Json::Value root;
+ SaveStatsJson( root );
RString fn = sDir + STATS_JSON_GZ;
RageFile f;
@@ -996,67 +1059,6 @@ void Profile::SaveEditableDataToDir( RSt
ini.WriteFile( sDir + EDITABLE_INI );
}
-const RString MeterToString(int i)
-{
- return ssprintf("%d",i);
-}
-
-int StringToMeter(const RString &s)
-{
- return atoi(s);
-}
-
-void Profile::SaveGeneral( Json::Value &root ) const
-{
- // These are write-only elements that are normally never read again.
- // This data is required by other apps (like internet ranking), but is
- // redundant to the game app.
- root["DisplayName"] = GetDisplayNameOrHighScoreName();
- root["CharacterID"] = m_sCharacterID;
- root["LastUsedHighScoreName"] = m_sLastUsedHighScoreName;
- root["WeightPounds"] = m_iWeightPounds;
- root["IsMachine"] = IsMachine();
- root["IsWeightSet"] = m_iWeightPounds != 0;
-
- root["Guid"] = m_sGuid;
- root["SortOrder"] = SortOrderToString(m_SortOrder);
- root["LastDifficulty"] = DifficultyToString(m_LastDifficulty);
- root["LastCourseDifficulty"] = CourseDifficultyToString(m_LastCourseDifficulty);
- m_lastSong.Serialize( root["LastSong"] );
- m_lastCourse.Serialize( root["LastCourse"] );
- root["TotalPlays"] = m_iTotalPlays;
- root["TotalPlaySeconds"] = m_iTotalPlaySeconds;
- root["TotalGameplaySeconds"] = m_iTotalGameplaySeconds;
- root["CurrentCombo"] = m_iCurrentCombo;
- root["TotalCaloriesBurned"] = m_fTotalCaloriesBurned;
- root["GoalType"] = m_GoalType;
- root["GoalCalories"] = m_iGoalCalories;
- root["GoalSeconds"] = m_iGoalSeconds;
- root["LastPlayedMachineGuid"] = m_sLastPlayedMachineGuid;
- root["LastPlayedDate"] = m_LastPlayedDate.GetString();
- root["TotalDancePoints"] = m_iTotalDancePoints;
- root["NumExtraStagesPassed"] = m_iNumExtraStagesPassed;
- root["NumExtraStagesFailed"] = m_iNumExtraStagesFailed;
- root["NumToasties"] = m_iNumToasties;
- root["TotalTapsAndHolds"] = m_iTotalTapsAndHolds;
- root["TotalJumps"] = m_iTotalJumps;
- root["TotalHolds"] = m_iTotalHolds;
- root["TotalRolls"] = m_iTotalRolls;
- root["TotalMines"] = m_iTotalMines;
- root["TotalHands"] = m_iTotalHands;
- root["SavedLuaData"] = m_SavedLuaData.Serialize();
- root["NumTotalSongsPlayed"] = m_iNumTotalSongsPlayed;
-
- JsonUtil::SerializeValueToValueMap( m_DefaultModifiersByGame, root["DefaultModifiersByGame"] );
- JsonUtil::SerializeArrayValues( m_UnlockedEntryIDs, root["UnlockEntryIDs"] );
- JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByPlayMode, PlayModeToString, root["NumSongsPlayedByPlayMode"] );
- JsonUtil::SerializeObjectToValueMapAsArray(m_iNumSongsPlayedByStyle, "Style", "NumPlays", root["NumSongsPlayedByStyle"] );
- JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByDifficulty, DifficultyToString, root["NumSongsPlayedByDifficulty"] );
- JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByMeter, MeterToString, root["NumSongsPlayedByMeter"] );
- JsonUtil::SerializeStringToValueMap( m_iNumStagesPassedByPlayMode, PlayModeToString, root["NumStagesPassedByPlayMode"] );
- JsonUtil::SerializeStringToValueMap( m_iNumStagesPassedByGrade, GradeToString, root["NumStagesPassedByGrade"] );
-}
-
ProfileLoadResult Profile::LoadEditableDataFromDir( RString sDir )
{
RString fn = sDir + EDITABLE_INI;
Modified: branches/4.0/stepmania/src/Profile.h
==============================================================================
--- branches/4.0/stepmania/src/Profile.h (original)
+++ branches/4.0/stepmania/src/Profile.h Sun Jan 16 01:15:02 2011
@@ -330,8 +330,8 @@ public:
void LoadGeneral( const Json::Value &root );
void SaveEditableDataToDir( RString sDir ) const;
+ void SaveStatsJson( Json::Value &root ) const;
bool SaveStatsJsonToDir( RString sDir, bool bSignData ) const;
- void SaveGeneral( Json::Value &root ) const;
void SaveStatsWebPageToDir( RString sDir ) const;
void SaveMachinePublicKeyToDir( RString sDir ) const;
Modified: branches/4.0/stepmania/src/ProfileManager.cpp
==============================================================================
--- branches/4.0/stepmania/src/ProfileManager.cpp (original)
+++ branches/4.0/stepmania/src/ProfileManager.cpp Sun Jan 16 01:15:02 2011
@@ -23,6 +23,8 @@
#include "HighScore.h"
#include "Character.h"
#include "CharacterManager.h"
+#include "FileDownload.h"
+#include "ScreenManager.h"
ProfileManager* PROFILEMAN = NULL; // global and accessable from anywhere in our program
@@ -288,18 +290,6 @@ bool ProfileManager::FastLoadProfileName
return false;
}
-void ProfileManager::SaveAllProfiles() const
-{
- this->SaveMachineProfile();
-
- FOREACH_HumanPlayer( pn )
- {
- if( !IsPersistentProfile(pn) )
- continue;
-
- this->SaveProfile( pn );
- }
-}
bool ProfileManager::SaveProfile( PlayerNumber pn ) const
{
@@ -519,6 +509,21 @@ void ProfileManager::SaveMachineProfile(
m_pMachineProfile->SaveAllToDir( MACHINE_PROFILE_DIR, false ); /* don't sign machine profiles */
}
+void ProfileManager::UploadMachineProfie() const
+{
+ //TODO: Copy the stats file to temp before uploaing
+ RString sFile = MACHINE_PROFILE_DIR+"Stats.json.gz";
+ RString sUrl = "unknown url";
+ {
+ FileTransfer ft;
+ // TODO: Don't stream file because it will block future writes.
+ ft.StartUpload( "http://www.stepmania.com/api.php?action=upload_stats", sFile, "" );
+ ft.BlockUntilFinished();
+ if( ft.GetResponseCode() != 200 )
+ SCREENMAN->SystemMessage( "Bad response code upload_stats " + ft.GetResponseCode() );
+ }
+}
+
void ProfileManager::LoadMachineProfile()
{
ProfileLoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false);
Modified: branches/4.0/stepmania/src/ProfileManager.h
==============================================================================
--- branches/4.0/stepmania/src/ProfileManager.h (original)
+++ branches/4.0/stepmania/src/ProfileManager.h Sun Jan 16 01:15:02 2011
@@ -66,6 +66,7 @@ public:
//
void LoadMachineProfile();
void SaveMachineProfile() const;
+ void UploadMachineProfie() const;
bool IsPersistentProfile( PlayerNumber pn ) const { return !m_sProfileDir[pn].empty(); }
bool IsPersistentProfile( ProfileSlot slot ) const;
|
|
From: Chris D. <de...@st...> - 2011-01-16 08:59:47
|
Modified:
branches/4.0/stepmania/src/ExportPackage.cpp
Log:
handle response to publish as JSON, not XML
Modified: branches/4.0/stepmania/src/ExportPackage.cpp
==============================================================================
--- branches/4.0/stepmania/src/ExportPackage.cpp (original)
+++ branches/4.0/stepmania/src/ExportPackage.cpp Sun Jan 16 00:59:39 2011
@@ -12,6 +12,8 @@
#include "FileDownload.h"
#include "XmlFile.h"
#include "arch/ArchHooks/ArchHooks.h"
+#include "Json/Value.h"
+#include "JsonUtil.h"
static RString ReplaceInvalidFileNameChars( RString sOldFileName )
{
@@ -120,15 +122,12 @@ RString PublishSong( const Song *pSong )
ft.BlockUntilFinished();
if( ft.GetResponseCode() != 200 )
return "Bad response code upload_song " + ft.GetResponseCode();
- XNode xml;
- PARSEINFO pi;
- xml.Load( ft.GetResponse(), &pi );
- if( pi.error_occur )
- return "Error parsing upload_song " + pi.error_string;
- if( xml.m_sName != "upload_song" )
- return "Unexpected response in upload_song";
- if( xml.GetChildValue("url", sUrl) )
- HOOKS->GoToURL(sUrl);
+ RString sResponse = ft.GetResponse();
+ Json::Value root;
+ RString sError;
+ if( !JsonUtil::LoadFromString(root,sResponse,sError) )
+ return "Error parsing response: " + sError;
+ HOOKS->GoToURL(root["url"].asString());
}
return "Published as '" + sUrl + "'";
|
|
From: Shakesoda <de...@st...> - 2011-01-01 22:24:25
|
Modified:
branches/4.0/stepmania/src/JsonUtil.h
Log:
Fix compile errors on GCC due to missing typename keyword.
Modified: branches/4.0/stepmania/src/JsonUtil.h
==============================================================================
--- branches/4.0/stepmania/src/JsonUtil.h (original)
+++ branches/4.0/stepmania/src/JsonUtil.h Sat Jan 1 14:24:18 2011
@@ -41,7 +41,7 @@ namespace JsonUtil
root = Json::Value(Json::arrayValue);
root.resize( v.size() );
int i=0;
- for( V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
+ for( typename V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
fn( *iter, root[i++] );
}
@@ -51,7 +51,7 @@ namespace JsonUtil
root = Json::Value(Json::arrayValue);
root.resize( v.size() );
int i=0;
- for( V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
+ for( typename V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
root[i++] = *iter;
}
@@ -61,28 +61,28 @@ namespace JsonUtil
root = Json::Value(Json::arrayValue);
root.resize( v.size() );
int i=0;
- for( V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
+ for( typename V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
iter->Serialize( root[i++] );
}
template <typename M, typename E, typename F>
static void SerializeStringToObjectMap(const M &m, F fnEnumToString(E e), Json::Value &root)
{
- for( M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
+ for( typename M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
iter->second.Serialize( root[ fnEnumToString(iter->first) ] );
}
template <typename M, typename E, typename F>
static void SerializeStringToValueMap(const M &m, F fnToString(E e), Json::Value &root)
{
- for( M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
+ for( typename M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
root[ fnToString(iter->first) ] = iter->second;
}
template <typename M>
static void SerializeValueToValueMap(const M &m, Json::Value &root)
{
- for( M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
+ for( typename M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
root[ (iter->first) ] = iter->second;
}
@@ -93,7 +93,7 @@ namespace JsonUtil
root = Json::Value(Json::arrayValue);
root.resize( v.size() );
int i=0;
- for( V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
+ for( typename V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
{
Json::Value &v = root[i++];
iter->first.Serialize( v[sKeyName] );
@@ -107,7 +107,7 @@ namespace JsonUtil
root = Json::Value(Json::arrayValue);
root.resize( v.size() );
int i=0;
- for( V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
+ for( typename V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
{
Json::Value &v = root[i++];
iter->first.Serialize( v[sKeyName] );
|
|
From: Chris D. <de...@st...> - 2011-01-01 21:34:18
|
Modified: branches/4.0/stepmania/Themes/default/BGAnimations/ScreenTitleMenu overlay.xml branches/4.0/stepmania/Themes/default/Languages/en.ini Log: title screen login Modified: branches/4.0/stepmania/Themes/default/BGAnimations/ScreenTitleMenu overlay.xml ============================================================================== --- branches/4.0/stepmania/Themes/default/BGAnimations/ScreenTitleMenu overlay.xml (original) +++ branches/4.0/stepmania/Themes/default/BGAnimations/ScreenTitleMenu overlay.xml Sat Jan 1 13:34:12 2011 @@ -2,8 +2,8 @@ <Layer Type="BitmapText" Font="Common normal" - Text="@ProductVersion()" - OnCommand="x,SCREEN_RIGHT-20;y,SCREEN_TOP+20;horizalign,right;diffuse,0.6,0.6,0.6,1;zoom,0.5;shadowlength,2" + Text="" + OnCommand="x,SCREEN_RIGHT-20;y,SCREEN_TOP+20;horizalign,right;diffuse,0.6,0.6,0.6,1;zoom,0.5;shadowlength,2;playcommand,Set;settext,GetStepManiaLoginMessage()..'\n'..ProductVersion()" /> <Layer Type="BitmapText" Modified: branches/4.0/stepmania/Themes/default/Languages/en.ini ============================================================================== --- branches/4.0/stepmania/Themes/default/Languages/en.ini (original) +++ branches/4.0/stepmania/Themes/default/Languages/en.ini Sat Jan 1 13:34:12 2011 @@ -1734,3 +1734,7 @@ HelpText= [ScreenNetSelectMusic] HelpText=Ctrl + Enter to enter room/select song + +[ScreenInstallOverlay] +Logged in as %s=Logged in as %s +Press %s to log in=Press %s to log in |
|
From: Chris D. <de...@st...> - 2011-01-01 21:30:41
|
Modified:
branches/4.0/stepmania/src/FileDownload.cpp
branches/4.0/stepmania/src/FileDownload.h
branches/4.0/stepmania/src/ScreenInstallOverlay.cpp
branches/4.0/stepmania/src/ScreenInstallOverlay.h
Log:
title screen login
json-encoded launch data on command line for login
Modified: branches/4.0/stepmania/src/FileDownload.cpp
==============================================================================
--- branches/4.0/stepmania/src/FileDownload.cpp (original)
+++ branches/4.0/stepmania/src/FileDownload.cpp Sat Jan 1 13:30:34 2011
@@ -378,6 +378,33 @@ void FileTransfer::BlockUntilFinished()
}
}
+RString FileTransfer::DecodeUrl(const RString &sUrl)
+{
+ string buffer;
+ int len = sUrl.length();
+
+ for (int i = 0; i < len; i++)
+ {
+ int j = i ;
+ char ch = sUrl.at(j);
+ if (ch == '%')
+ {
+ char tmpstr[] = "0x0__";
+ int chnum;
+ tmpstr[3] = sUrl.at(j+1);
+ tmpstr[4] = sUrl.at(j+2);
+ chnum = strtol(tmpstr, NULL, 16);
+ buffer += (char)chnum;
+ i += 2;
+ }
+ else
+ {
+ buffer += ch;
+ }
+ }
+ return buffer;
+}
+
#endif
/*
* (c) 2004 Charles Lohr, Chris Danford
Modified: branches/4.0/stepmania/src/FileDownload.h
==============================================================================
--- branches/4.0/stepmania/src/FileDownload.h (original)
+++ branches/4.0/stepmania/src/FileDownload.h Sat Jan 1 13:30:34 2011
@@ -22,6 +22,8 @@ public:
int GetResponseCode() const { return m_iResponseCode; }
RString GetResponse() const { return m_sBUFFER; }
RString GetStatus() const { return m_sStatus; }
+
+ static RString DecodeUrl(const RString &sUrl);
private:
enum TransferType { download, upload };
void StartTransfer( TransferType type, const RString &sURL, const RString &sSrcFile, const RString &sDestFile );
Modified: branches/4.0/stepmania/src/ScreenInstallOverlay.cpp
==============================================================================
--- branches/4.0/stepmania/src/ScreenInstallOverlay.cpp (original)
+++ branches/4.0/stepmania/src/ScreenInstallOverlay.cpp Sat Jan 1 13:30:34 2011
@@ -16,6 +16,10 @@ class Song;
#include "SongManager.h"
#include "CommandLineActions.h"
#include "ScreenDimensions.h"
+#include "InputEventPlus.h"
+#include "arch/ArchHooks/ArchHooks.h"
+#include "LuaFunctions.h"
+#include "FileDownload.h"
struct PlayAfterLaunchInfo
{
@@ -123,26 +127,33 @@ struct FileCopyResult
RString sFile, sComment;
};
+Preference<RString> g_sUsername( "Username", "" );
Preference<RString> g_sCookie( "Cookie", "" );
+static LocalizedString LOGGED_IN_AS ( "ScreenInstallOverlay", "Logged in as %s" );
+static LocalizedString PRESS_TO_LOG_IN ( "ScreenInstallOverlay", "Press %s to log in" );
+static const DeviceButton g_buttonLogin = KEY_F11;
+RString GetStepManiaLoginMessage()
+{
+ if( g_sUsername.Get().length() > 0 )
+ return ssprintf(LOGGED_IN_AS.GetValue(), g_sUsername.Get().c_str());
+ const RString &sKey = DeviceButtonToString( g_buttonLogin );
+ return ssprintf( PRESS_TO_LOG_IN.GetValue(), sKey.c_str() );
+}
+LuaFunction( GetStepManiaLoginMessage, GetStepManiaLoginMessage() );
+
+class DownloadTask;
+static vector<DownloadTask*> g_pDownloadTasks;
+PlayAfterLaunchInfo g_playAfterLaunchInfo;
+void HandleLaunch( RString sJson );
class DownloadTask
{
+protected:
FileTransfer *m_pTransfer;
- vector<RString> m_vsQueuedPackageUrls;
- RString m_sCurrentPackageTempFile;
- enum
- {
- control,
- packages
- } m_DownloadState;
- PlayAfterLaunchInfo m_playAfterLaunchInfo;
public:
- DownloadTask(const RString &sControlFileUri)
+ DownloadTask()
{
- //SCREENMAN->SystemMessage( "Downloading control file." );
- m_pTransfer = new FileTransfer();
- m_pTransfer->StartDownload( sControlFileUri, "" );
- m_DownloadState = control;
+ m_pTransfer = NULL;
}
~DownloadTask()
{
@@ -155,102 +166,86 @@ public:
else
return m_pTransfer->GetStatus();
}
+ virtual bool UpdateAndIsFinished( float fDeltaSeconds, PlayAfterLaunchInfo &playAfterLaunchInfo ) = 0;
+};
+class DownloadLaunchTask : public DownloadTask
+{
+public:
+ DownloadLaunchTask( const RString &sUrl )
+ {
+ m_pTransfer = new FileTransfer();
+ m_pTransfer->StartDownload( sUrl, "" );
+ }
bool UpdateAndIsFinished( float fDeltaSeconds, PlayAfterLaunchInfo &playAfterLaunchInfo )
{
m_pTransfer->Update( fDeltaSeconds );
- switch( m_DownloadState )
+ if( m_pTransfer->IsFinished() )
{
- case control:
- if( m_pTransfer->IsFinished() )
- {
- SCREENMAN->SystemMessage( "Downloading required .smzip" );
+ RString sJsonResponse = m_pTransfer->GetResponse();
+ SAFE_DELETE( m_pTransfer );
+ HandleLaunch( sJsonResponse );
+ return true;
+ }
+ return false;
+ }
+};
+class DownloadPackagesTask : public DownloadTask
+{
+ vector<RString> m_vsQueuedPackageUrls;
+ RString m_sCurrentPackageTempFile;
+ PlayAfterLaunchInfo m_playAfterLaunchInfo;
+public:
+ DownloadPackagesTask( vector<RString> vsQueuedPackageUrls, PlayAfterLaunchInfo pali )
+ {
+ m_vsQueuedPackageUrls = vsQueuedPackageUrls;
+ m_playAfterLaunchInfo = pali;
- RString sResponse = m_pTransfer->GetResponse();
- SAFE_DELETE( m_pTransfer );
+ if( m_vsQueuedPackageUrls.size() > 0 )
+ SCREENMAN->SystemMessage( "Downloading required .smzip" );
+
+ /*
+ {
+ // TODO: Validate that this zip contains files for this version of StepMania
+
+ bool bFileExists = DoesFileExist( SpecialFiles::PACKAGES_DIR + sFilename + sExt );
+ if( FileCopy( TEMP_MOUNT_POINT + sFilename + sExt, SpecialFiles::PACKAGES_DIR + sFilename + sExt ) )
+ vSucceeded.push_back( FileCopyResult(*s,bFileExists ? "overwrote existing file" : "") );
+ else
+ vFailed.push_back( FileCopyResult(*s,ssprintf("error copying file to '%s'",sOsDir.c_str())) );
- Json::Value root;
- RString sError;
- if( !JsonUtil::LoadFromString(root, sResponse, sError) )
- {
- SCREENMAN->SystemMessage( sError );
- return true;
- }
-
- // Parse the JSON response, make a list of all packages need to be downloaded.
- {
- if( root["Cookie"].isString() )
- g_sCookie.Set( root["Cookie"].asString() );
- Json::Value require = root["Require"];
- if( require.isArray() )
- {
- for( unsigned i=0; i<require.size(); i++)
- {
- Json::Value iter = require[i];
- if( iter["Dir"].isString() )
- {
- RString sDir = iter["Dir"].asString();
- Parse( sDir, m_playAfterLaunchInfo );
- if( DoesFileExist( sDir ) )
- continue;
- }
-
- RString sUri;
- if( iter["Uri"].isString() )
- {
- sUri = iter["Uri"].asString();
- m_vsQueuedPackageUrls.push_back( sUri );
- }
- }
- }
- }
-
- /*
- {
- // TODO: Validate that this zip contains files for this version of StepMania
-
- bool bFileExists = DoesFileExist( SpecialFiles::PACKAGES_DIR + sFilename + sExt );
- if( FileCopy( TEMP_MOUNT_POINT + sFilename + sExt, SpecialFiles::PACKAGES_DIR + sFilename + sExt ) )
- vSucceeded.push_back( FileCopyResult(*s,bFileExists ? "overwrote existing file" : "") );
- else
- vFailed.push_back( FileCopyResult(*s,ssprintf("error copying file to '%s'",sOsDir.c_str())) );
-
- }
- */
- m_DownloadState = packages;
- if( !m_vsQueuedPackageUrls.empty() )
- {
- RString sUrl = m_vsQueuedPackageUrls.back();
- m_vsQueuedPackageUrls.pop_back();
- m_sCurrentPackageTempFile = MakeTempFileName(sUrl);
- ASSERT(m_pTransfer == NULL);
- m_pTransfer = new FileTransfer();
- m_pTransfer->StartDownload( sUrl, m_sCurrentPackageTempFile );
- }
- }
- break;
- case packages:
- {
- if( m_pTransfer->IsFinished() )
- {
- SAFE_DELETE( m_pTransfer );
- InstallSmzip( m_sCurrentPackageTempFile, m_playAfterLaunchInfo );
- FILEMAN->Remove( m_sCurrentPackageTempFile ); // Harmless if this fails because download didn't finish
- }
- if( !m_vsQueuedPackageUrls.empty() )
- {
- RString sUrl = m_vsQueuedPackageUrls.back();
- m_vsQueuedPackageUrls.pop_back();
- m_sCurrentPackageTempFile = MakeTempFileName(sUrl);
- ASSERT(m_pTransfer == NULL);
- m_pTransfer = new FileTransfer();
- m_pTransfer->StartDownload( sUrl, m_sCurrentPackageTempFile );
- }
- }
- break;
}
- bool bFinsihed = m_DownloadState == packages &&
- m_vsQueuedPackageUrls.empty() &&
- m_pTransfer == NULL;
+ */
+ if( !m_vsQueuedPackageUrls.empty() )
+ {
+ RString sUrl = m_vsQueuedPackageUrls.back();
+ m_vsQueuedPackageUrls.pop_back();
+ m_sCurrentPackageTempFile = MakeTempFileName(sUrl);
+ ASSERT(m_pTransfer == NULL);
+ m_pTransfer = new FileTransfer();
+ m_pTransfer->StartDownload( sUrl, m_sCurrentPackageTempFile );
+ }
+ }
+
+ bool UpdateAndIsFinished( float fDeltaSeconds, PlayAfterLaunchInfo &playAfterLaunchInfo )
+ {
+ m_pTransfer->Update( fDeltaSeconds );
+ if( m_pTransfer->IsFinished() )
+ {
+ SAFE_DELETE( m_pTransfer );
+ InstallSmzip( m_sCurrentPackageTempFile, m_playAfterLaunchInfo );
+ FILEMAN->Remove( m_sCurrentPackageTempFile ); // Harmless if this fails because download didn't finish
+ }
+ if( !m_vsQueuedPackageUrls.empty() )
+ {
+ RString sUrl = m_vsQueuedPackageUrls.back();
+ m_vsQueuedPackageUrls.pop_back();
+ m_sCurrentPackageTempFile = MakeTempFileName(sUrl);
+ ASSERT(m_pTransfer == NULL);
+ m_pTransfer = new FileTransfer();
+ m_pTransfer->StartDownload( sUrl, m_sCurrentPackageTempFile );
+ }
+
+ bool bFinsihed = m_vsQueuedPackageUrls.empty() && m_pTransfer == NULL;
if( bFinsihed )
{
playAfterLaunchInfo = m_playAfterLaunchInfo;
@@ -266,10 +261,67 @@ public:
return SpecialFiles::CACHE_DIR + "Downloads/" + Basename(s);
}
};
-static vector<DownloadTask*> g_pDownloadTasks;
+void HandleLaunch( RString sJson )
+{
+ Json::Value root;
+ RString sError;
+ if( !JsonUtil::LoadFromString(root, sJson, sError) )
+ {
+ SCREENMAN->SystemMessage( sError );
+ return;
+ }
-static bool IsStepManiaProtocol(const RString &arg)
+ // Parse the JSON response, make a list of all packages need to be downloaded.
+ if( root["Username"].isString() )
+ {
+ g_sUsername.Set( root["Username"].asString() );
+ SCREENMAN->SystemMessage("Logged in as " + g_sUsername.Get() );
+ }
+ if( root["Cookie"].isString() )
+ g_sCookie.Set( root["Cookie"].asString() );
+ Json::Value require = root["Require"];
+ vector<RString> vsQueuedPackageUrls;
+ PlayAfterLaunchInfo pali;
+ if( require.isArray() )
+ {
+ for( unsigned i=0; i<require.size(); i++)
+ {
+ Json::Value iter = require[i];
+ if( iter["Dir"].isString() )
+ {
+ RString sDir = iter["Dir"].asString();
+ Parse( sDir, pali );
+ if( DoesFileExist( sDir ) )
+ continue;
+ }
+
+ RString sUri;
+ if( iter["Uri"].isString() )
+ {
+ sUri = iter["Uri"].asString();
+ vsQueuedPackageUrls.push_back( sUri );
+ }
+ }
+ }
+ if( vsQueuedPackageUrls.size() > 0 )
+ g_pDownloadTasks.push_back( new DownloadPackagesTask(vsQueuedPackageUrls, pali) );
+ else
+ g_playAfterLaunchInfo.OverlayWith( pali );
+}
+
+static bool HandleStepManiaProtocolLaunch(const RString &arg)
+{
+ static const RString sBeginning = "stepmania://launch/?"; // "launch" is a dummy server name. There's a slash after it because browsers will insert it if we leave out the slash between server and '?'
+ if( !BeginsWith(arg,sBeginning) )
+ return false;
+ RString sQueryString = arg.Right( arg.size() - sBeginning.size() );
+ RString sJson = FileTransfer::DecodeUrl(sQueryString);
+ HandleLaunch(sJson);
+ return true;
+}
+
+static bool IsStepManiaProtocolFile(const RString &arg)
{
// for now, only load from the StepMania domain until the security implications of this feature are better understood.
return BeginsWith(arg,"stepmania://beta.stepmania.com/");
@@ -287,8 +339,10 @@ PlayAfterLaunchInfo DoInstalls( CommandL
for( int i = 0; i<(int)args.argv.size(); i++ )
{
RString s = args.argv[i];
- if( IsStepManiaProtocol(s) )
- g_pDownloadTasks.push_back( new DownloadTask(s) );
+ if( HandleStepManiaProtocolLaunch(s) )
+ ;
+ else if( IsStepManiaProtocolFile(s) )
+ g_pDownloadTasks.push_back( new DownloadLaunchTask(s) );
else if( IsSmzip(s) )
InstallSmzipOsArg(s, ret);
}
@@ -315,16 +369,27 @@ void ScreenInstallOverlay::Init()
this->AddChild( &m_textStatus );
}
+bool ScreenInstallOverlay::OverlayInput( const InputEventPlus &input )
+{
+ if( input.DeviceI.button == g_buttonLogin )
+ {
+ HOOKS->GoToURL("http://www.stepmania.com/launch.php");
+ return true;
+ }
+
+ return false;
+}
+
+
void ScreenInstallOverlay::Update( float fDeltaTime )
{
Screen::Update(fDeltaTime);
- PlayAfterLaunchInfo playAfterLaunchInfo;
while( CommandLineActions::ToProcess.size() > 0 )
{
CommandLineActions::CommandLineArgs args = CommandLineActions::ToProcess.back();
CommandLineActions::ToProcess.pop_back();
PlayAfterLaunchInfo pali2 = DoInstalls( args );
- playAfterLaunchInfo.OverlayWith( pali2 );
+ g_playAfterLaunchInfo.OverlayWith( pali2 );
}
for(int i=g_pDownloadTasks.size()-1; i>=0; --i)
@@ -333,7 +398,7 @@ void ScreenInstallOverlay::Update( float
PlayAfterLaunchInfo pali;
if( p->UpdateAndIsFinished( fDeltaTime, pali) )
{
- playAfterLaunchInfo.OverlayWith(pali);
+ g_playAfterLaunchInfo.OverlayWith(pali);
SAFE_DELETE(p);
g_pDownloadTasks.erase( g_pDownloadTasks.begin()+i );
}
@@ -348,17 +413,17 @@ void ScreenInstallOverlay::Update( float
m_textStatus.SetText( join("\n", vsMessages) );
}
- if( playAfterLaunchInfo.bAnySongChanged )
+ if( g_playAfterLaunchInfo.bAnySongChanged )
SONGMAN->Reload( false, NULL );
- if( !playAfterLaunchInfo.sSongDir.empty() )
+ if( !g_playAfterLaunchInfo.sSongDir.empty() )
{
Song* pSong = NULL;
GAMESTATE->Reset();
RString sInitialScreen;
- if( playAfterLaunchInfo.sSongDir.length() > 0 )
- pSong = SONGMAN->GetSongFromDir( playAfterLaunchInfo.sSongDir );
+ if( g_playAfterLaunchInfo.sSongDir.length() > 0 )
+ pSong = SONGMAN->GetSongFromDir( g_playAfterLaunchInfo.sSongDir );
if( pSong )
{
vector<const Style*> vpStyle;
@@ -375,7 +440,9 @@ void ScreenInstallOverlay::Update( float
{
sInitialScreen = CommonMetrics::INITIAL_SCREEN;
}
-
+
+ g_playAfterLaunchInfo = PlayAfterLaunchInfo();
+
SCREENMAN->SetNewScreen( sInitialScreen );
}
}
Modified: branches/4.0/stepmania/src/ScreenInstallOverlay.h
==============================================================================
--- branches/4.0/stepmania/src/ScreenInstallOverlay.h (original)
+++ branches/4.0/stepmania/src/ScreenInstallOverlay.h Sat Jan 1 13:30:34 2011
@@ -12,6 +12,7 @@ public:
virtual ~ScreenInstallOverlay();
virtual void Init();
+ bool OverlayInput( const InputEventPlus &input );
void Update( float fDeltaTime );
private:
|
|
From: Chris D. <de...@st...> - 2010-12-30 22:22:59
|
Modified: branches/4.0/stepmania/src/Profile.cpp Log: read from deflated stream, not basic stream (fix profile reading) Modified: branches/4.0/stepmania/src/Profile.cpp ============================================================================== --- branches/4.0/stepmania/src/Profile.cpp (original) +++ branches/4.0/stepmania/src/Profile.cpp Thu Dec 30 14:22:52 2010 @@ -856,7 +856,7 @@ ProfileLoadResult Profile::LoadAllFromDi LOG->Trace( "Loading %s", fn.c_str() ); Json::Value root; - if( !JsonUtil::LoadFromFileShowErrors(root, *pFile.get()) ) + if( !JsonUtil::LoadFromFileShowErrors(root, *pInflate.get()) ) return ProfileLoadResult_FailedTampered; LOG->Trace( "Done." ); |
|
From: Chris D. <de...@st...> - 2010-12-30 21:29:16
|
Modified:
branches/4.0/stepmania/src/JsonUtil.cpp
branches/4.0/stepmania/src/JsonUtil.h
branches/4.0/stepmania/src/Profile.cpp
Log:
save profile data gzipped
Modified: branches/4.0/stepmania/src/JsonUtil.cpp
==============================================================================
--- branches/4.0/stepmania/src/JsonUtil.cpp (original)
+++ branches/4.0/stepmania/src/JsonUtil.cpp Thu Dec 30 13:29:09 2010
@@ -54,6 +54,17 @@ bool JsonUtil::LoadFromStringShowErrors(
bool JsonUtil::WriteFile( const Json::Value &root, const RString &sFile, bool bMinified )
{
+ RageFile f;
+ if( !f.Open(sFile, RageFile::WRITE) )
+ {
+ LOG->Warn("Couldn't open %s for reading: %s", sFile.c_str(), f.GetError().c_str() );
+ return false;
+ }
+ return WriteFile( root, f, bMinified );
+}
+
+bool JsonUtil::WriteFile( const Json::Value &root, RageFileBasic &f, bool bMinified )
+{
std::string s;
if( !bMinified )
{
@@ -66,12 +77,6 @@ bool JsonUtil::WriteFile( const Json::Va
s = writer.write(root);
}
- RageFile f;
- if( !f.Open(sFile, RageFile::WRITE) )
- {
- LOG->Warn("Couldn't open %s for reading: %s", sFile.c_str(), f.GetError().c_str() );
- return false;
- }
f.Write(s);
return true;
}
Modified: branches/4.0/stepmania/src/JsonUtil.h
==============================================================================
--- branches/4.0/stepmania/src/JsonUtil.h (original)
+++ branches/4.0/stepmania/src/JsonUtil.h Thu Dec 30 13:29:09 2010
@@ -15,6 +15,7 @@ namespace JsonUtil
bool LoadFromFileShowErrors( Json::Value &root, RageFileBasic &f );
bool WriteFile( const Json::Value &root, const RString &sFile, bool bMinified );
+ bool WriteFile( const Json::Value &root, RageFileBasic &f, bool bMinified );
template<class T>
static void SerializeVectorObjects(const vector<T> &v, void fn(const T &, Json::Value &), Json::Value &root)
Modified: branches/4.0/stepmania/src/Profile.cpp
==============================================================================
--- branches/4.0/stepmania/src/Profile.cpp (original)
+++ branches/4.0/stepmania/src/Profile.cpp Thu Dec 30 13:29:09 2010
@@ -27,10 +27,12 @@
#include "Character.h"
#include "Json/Value.h"
#include "JsonUtil.h"
+#include "RageFile.h"
+#include "RageFileDriverDeflate.h"
const RString STATS_XSL = "Stats.xsl";
const RString COMMON_XSL = "Common.xsl";
-const RString STATS_JSON = "Stats.json";
+const RString STATS_JSON_GZ = "Stats.json.gz";
const RString EDITABLE_INI = "Editable.ini";
const RString DONT_SHARE_SIG = "DontShare.sig";
const RString PUBLIC_KEY_FILE = "public.key";
@@ -41,12 +43,7 @@ const RString EDIT_COURSES_SUBDIR = "Ed
#define GUID_SIZE_BYTES 8
#define MAX_EDITABLE_INI_SIZE_BYTES 2*1024 // 2KB
-#define MAX_PLAYER_STATS_JSON_SIZE_BYTES \
- 100 /* Songs */ \
- * 3 /* Steps per Song */ \
- * 10 /* HighScores per Steps */ \
- * 1024 /* size in bytes of a HighScores XNode */
-
+#define MAX_PLAYER_STATS_JSON_GZ_SIZE_BYTES 100*1024 // 100KB
const unsigned int DEFAULT_WEIGHT_POUNDS = 120;
#if defined(_MSC_VER)
@@ -797,40 +794,27 @@ ProfileLoadResult Profile::LoadAllFromDi
LoadEditableDataFromDir( sDir );
// Check for the existance of stats.xml
- RString fn = sDir + STATS_JSON;
+ RString fn = sDir + STATS_JSON_GZ;
if( !IsAFile(fn) )
return ProfileLoadResult_FailedNoProfile;
- //
- // Don't unreasonably large stats.xml files.
- //
- if( !IsMachine() ) // only check stats coming from the player
- {
- int iBytes = FILEMAN->GetFileSizeInBytes( fn );
- if( iBytes > MAX_PLAYER_STATS_JSON_SIZE_BYTES )
- {
- LOG->Warn( "The file '%s' is unreasonably large. It won't be loaded.", fn.c_str() );
- return ProfileLoadResult_FailedTampered;
- }
- }
-
if( bRequireSignature )
{
- RString sStatsXmlSigFile = fn+SIGNATURE_APPEND;
+ RString sSigFile = fn+SIGNATURE_APPEND;
RString sDontShareFile = sDir + DONT_SHARE_SIG;
LOG->Trace( "Verifying don't share signature" );
// verify the stats.xml signature with the "don't share" file
- if( !CryptManager::VerifyFileWithFile(sStatsXmlSigFile, sDontShareFile) )
+ if( !CryptManager::VerifyFileWithFile(sSigFile, sDontShareFile) )
{
- LOG->Warn( "The don't share check for '%s' failed. Data will be ignored.", sStatsXmlSigFile.c_str() );
+ LOG->Warn( "The don't share check for '%s' failed. Data will be ignored.", sSigFile.c_str() );
return ProfileLoadResult_FailedTampered;
}
LOG->Trace( "Done." );
// verify stats.xml
LOG->Trace( "Verifying stats.xml signature" );
- if( !CryptManager::VerifyFileWithFile(fn, sStatsXmlSigFile) )
+ if( !CryptManager::VerifyFileWithFile(fn, sSigFile) )
{
LOG->Warn( "The signature check for '%s' failed. Data will be ignored.", fn.c_str() );
return ProfileLoadResult_FailedTampered;
@@ -838,12 +822,46 @@ ProfileLoadResult Profile::LoadAllFromDi
LOG->Trace( "Done." );
}
+ int iError;
+ auto_ptr<RageFileBasic> pFile( FILEMAN->Open(fn, RageFile::READ, iError) );
+ if( pFile.get() == NULL )
+ {
+ LOG->Trace( "Error opening %s: %s", fn.c_str(), strerror(iError) );
+ return ProfileLoadResult_FailedTampered;
+ }
+
+ RString sError;
+ uint32_t iCRC32;
+ RageFileBasic *pInflateTemp = GunzipFile( *pFile, sError, &iCRC32 );
+ if( pInflateTemp == NULL )
+ {
+ LOG->Trace( "Error opening %s: %s", fn.c_str(), sError.c_str() );
+ return ProfileLoadResult_FailedTampered;
+ }
+ auto_ptr<RageFileBasic> pInflate( pInflateTemp );
+
+
+ //
+ // Don't read unreasonably large stats.xml files.
+ //
+ if( !IsMachine() ) // only check stats coming from the player
+ {
+ int iBytes = FILEMAN->GetFileSizeInBytes( fn );
+ if( iBytes > MAX_PLAYER_STATS_JSON_GZ_SIZE_BYTES )
+ {
+ LOG->Warn( "The file '%s' is unreasonably large. It won't be loaded.", fn.c_str() );
+ return ProfileLoadResult_FailedTampered;
+ }
+ }
+
LOG->Trace( "Loading %s", fn.c_str() );
Json::Value root;
- if( !JsonUtil::LoadFromFileShowErrors(root, fn) )
+ if( !JsonUtil::LoadFromFileShowErrors(root, *pFile.get()) )
return ProfileLoadResult_FailedTampered;
LOG->Trace( "Done." );
+ pInflate.release();
+
return LoadStatsJson( root );
}
@@ -932,26 +950,38 @@ bool Profile::SaveStatsJsonToDir( RStrin
JsonUtil::SerializeArrayObjects( m_vRecentStepsScores, root["RecentSongScores"] );
JsonUtil::SerializeArrayObjects( m_vRecentCourseScores, root["RecentCourseScores"] );
- RString fn = sDir + STATS_JSON;
- bool bSaved = JsonUtil::WriteFile( root, fn, false );
+ RString fn = sDir + STATS_JSON_GZ;
+ RageFile f;
+ if( !f.Open(fn, RageFile::WRITE) )
+ {
+ LOG->Warn( "Couldn't open %s for writing: %s", fn.c_str(), f.GetError().c_str() );
+ return false;
+ }
+
+ RageFileObjGzip gzip( &f );
+ gzip.Start();
+ if( !JsonUtil::WriteFile( root, gzip, true ) )
+ return false;
+ if( gzip.Finish() == -1 )
+ return false;
// Update file cache, or else IsAFile in CryptManager won't see this new file.
FILEMAN->FlushDirCache( sDir );
- if( bSaved && bSignData )
+ if( bSignData )
{
- RString sStatsXmlSigFile = fn+SIGNATURE_APPEND;
- CryptManager::SignFileToFile(fn, sStatsXmlSigFile);
+ RString sSigFile = fn+SIGNATURE_APPEND;
+ CryptManager::SignFileToFile(fn, sSigFile);
- // Update file cache, or else IsAFile in CryptManager won't see sStatsXmlSigFile.
+ // Update file cache, or else IsAFile in CryptManager won't see sSigFile.
FILEMAN->FlushDirCache( sDir );
// Save the "don't share" file
RString sDontShareFile = sDir + DONT_SHARE_SIG;
- CryptManager::SignFileToFile(sStatsXmlSigFile, sDontShareFile);
+ CryptManager::SignFileToFile(sSigFile, sDontShareFile);
}
- return bSaved;
+ return true;
}
void Profile::SaveEditableDataToDir( RString sDir ) const
@@ -1332,8 +1362,8 @@ bool Profile::IsMachine() const
void Profile::MoveBackupToDir( RString sFromDir, RString sToDir )
{
FILEMAN->Move( sFromDir+EDITABLE_INI, sToDir+EDITABLE_INI );
- FILEMAN->Move( sFromDir+STATS_JSON, sToDir+STATS_JSON );
- FILEMAN->Move( sFromDir+STATS_JSON+SIGNATURE_APPEND, sToDir+STATS_JSON+SIGNATURE_APPEND );
+ FILEMAN->Move( sFromDir+STATS_JSON_GZ, sToDir+STATS_JSON_GZ );
+ FILEMAN->Move( sFromDir+STATS_JSON_GZ+SIGNATURE_APPEND, sToDir+STATS_JSON_GZ+SIGNATURE_APPEND );
FILEMAN->Move( sFromDir+DONT_SHARE_SIG, sToDir+DONT_SHARE_SIG );
}
|
|
From: Chris D. <de...@st...> - 2010-12-30 21:27:57
|
Modified: branches/4.0/stepmania/src/ScreenEdit.cpp Log: spacing cleanup Modified: branches/4.0/stepmania/src/ScreenEdit.cpp ============================================================================== --- branches/4.0/stepmania/src/ScreenEdit.cpp (original) +++ branches/4.0/stepmania/src/ScreenEdit.cpp Thu Dec 30 13:27:50 2010 @@ -478,7 +478,7 @@ static MenuDef g_MainMenu( MenuRowDef( ScreenEdit::play_current_beat_to_end, "Play current beat to end", true, EditMode_Practice, true, true, 0, NULL ), MenuRowDef( ScreenEdit::save, "Save", true, EditMode_Home, true, true, 0, NULL ), MenuRowDef( ScreenEdit::publish, "Publish to StepMania.com", true, EditMode_Home, true, true, 0, NULL ), - MenuRowDef( ScreenEdit::export_song, "Export .smzip to Desktop", true, EditMode_Home, true, true, 0, NULL ), + MenuRowDef( ScreenEdit::export_song, "Export .smzip to Desktop", true, EditMode_Home, true, true, 0, NULL ), MenuRowDef( ScreenEdit::revert_to_last_save, "Revert to last save", true, EditMode_Home, true, true, 0, NULL ), MenuRowDef( ScreenEdit::revert_from_disk, "Revert from disk", true, EditMode_Full, true, true, 0, NULL ), MenuRowDef( ScreenEdit::options, "Editor options", true, EditMode_Practice, true, true, 0, NULL ), |
|
From: Chris D. <de...@st...> - 2010-12-29 22:08:51
|
Modified:
branches/4.0/stepmania/src/CourseUtil.cpp
branches/4.0/stepmania/src/CourseUtil.h
branches/4.0/stepmania/src/HighScore.cpp
branches/4.0/stepmania/src/HighScore.h
branches/4.0/stepmania/src/JsonUtil.h
branches/4.0/stepmania/src/NotesLoaderJson.cpp
branches/4.0/stepmania/src/Profile.cpp
branches/4.0/stepmania/src/Profile.h
branches/4.0/stepmania/src/SongUtil.cpp
branches/4.0/stepmania/src/SongUtil.h
branches/4.0/stepmania/src/StepsUtil.cpp
branches/4.0/stepmania/src/StepsUtil.h
branches/4.0/stepmania/src/StyleUtil.cpp
branches/4.0/stepmania/src/StyleUtil.h
branches/4.0/stepmania/src/TrailUtil.cpp
branches/4.0/stepmania/src/TrailUtil.h
branches/4.0/stepmania/src/UnlockManager.cpp
Log:
-return success/failure from Deserialize for graceful error handling
-finish Profile JSON deserializing
Modified: branches/4.0/stepmania/src/CourseUtil.cpp
==============================================================================
--- branches/4.0/stepmania/src/CourseUtil.cpp (original)
+++ branches/4.0/stepmania/src/CourseUtil.cpp Wed Dec 29 14:08:42 2010
@@ -403,10 +403,11 @@ void CourseID::Serialize( Json::Value &r
root["FullTitle"] = sFullTitle;
}
-void CourseID::Deserialize( const Json::Value &root )
+bool CourseID::Deserialize( const Json::Value &root )
{
sPath = root["Path"].asString();
sFullTitle = root["FullTitle"].asString();
+ return true;
}
RString CourseID::ToString() const
Modified: branches/4.0/stepmania/src/CourseUtil.h
==============================================================================
--- branches/4.0/stepmania/src/CourseUtil.h (original)
+++ branches/4.0/stepmania/src/CourseUtil.h Wed Dec 29 14:08:42 2010
@@ -56,7 +56,7 @@ public:
void LoadFromNode( const XNode* pNode );
void Serialize( Json::Value &root ) const;
- void Deserialize( const Json::Value &root );
+ bool Deserialize( const Json::Value &root );
RString ToString() const;
bool IsValid() const;
Modified: branches/4.0/stepmania/src/HighScore.cpp
==============================================================================
--- branches/4.0/stepmania/src/HighScore.cpp (original)
+++ branches/4.0/stepmania/src/HighScore.cpp Wed Dec 29 14:08:42 2010
@@ -391,13 +391,14 @@ void HighScoreList::Serialize( Json::Val
JsonUtil::SerializeArrayObjects( vHighScores, root["HighScores"] );
}
-void HighScoreList::Deserialize( const Json::Value &root )
+bool HighScoreList::Deserialize( const Json::Value &root )
{
Init();
root["NumTimesPlayed"].TryGet( iNumTimesPlayed );
dtLastPlayed.FromString( root["LastPlayed"].asString() );
JsonUtil::DeserializeArrayObjects( vHighScores, root["HighScores"] );
+ return true;
}
Modified: branches/4.0/stepmania/src/HighScore.h
==============================================================================
--- branches/4.0/stepmania/src/HighScore.h (original)
+++ branches/4.0/stepmania/src/HighScore.h Wed Dec 29 14:08:42 2010
@@ -95,7 +95,7 @@ public:
void LoadFromNode( const XNode* pNode );
void Serialize( Json::Value &root ) const;
- void Deserialize( const Json::Value &root );
+ bool Deserialize( const Json::Value &root );
vector<HighScore> vHighScores;
private:
Modified: branches/4.0/stepmania/src/JsonUtil.h
==============================================================================
--- branches/4.0/stepmania/src/JsonUtil.h (original)
+++ branches/4.0/stepmania/src/JsonUtil.h Wed Dec 29 14:08:42 2010
@@ -64,23 +64,30 @@ namespace JsonUtil
iter->Serialize( root[i++] );
}
- template <typename M, typename E>
- static void SerializeEnumToObjectMap(const M &m, const RString &fnEnumToString(E e), Json::Value &root)
+ template <typename M, typename E, typename F>
+ static void SerializeStringToObjectMap(const M &m, F fnEnumToString(E e), Json::Value &root)
{
for( M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
iter->second.Serialize( root[ fnEnumToString(iter->first) ] );
}
+ template <typename M, typename E, typename F>
+ static void SerializeStringToValueMap(const M &m, F fnToString(E e), Json::Value &root)
+ {
+ for( M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
+ root[ fnToString(iter->first) ] = iter->second;
+ }
+
template <typename M>
static void SerializeValueToValueMap(const M &m, Json::Value &root)
{
for( M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
- root[ (iter->first).GetString() ] = iter->second;
+ root[ (iter->first) ] = iter->second;
}
// Serialize a map that has a non-string key type
template <typename V>
- static void SerializeMapAsArray(const V &v, const RString &sKeyName, const RString &sValueName, Json::Value &root)
+ static void SerializeObjectToObjectMapAsArray(const V &v, const RString &sKeyName, const RString &sValueName, Json::Value &root)
{
root = Json::Value(Json::arrayValue);
root.resize( v.size() );
@@ -93,6 +100,20 @@ namespace JsonUtil
}
}
+ template <typename V>
+ static void SerializeObjectToValueMapAsArray(const V &v, const RString &sKeyName, const RString &sValueName, Json::Value &root)
+ {
+ root = Json::Value(Json::arrayValue);
+ root.resize( v.size() );
+ int i=0;
+ for( V::const_iterator iter=v.begin(); iter!=v.end(); iter++ )
+ {
+ Json::Value &v = root[i++];
+ iter->first.Serialize( v[sKeyName] );
+ v[sValueName] = iter->second;
+ }
+ }
+
template<class T>
static void DeserializeVectorObjects(vector<T> &v, void fn(T &, const Json::Value &), const Json::Value &root)
{
@@ -123,11 +144,96 @@ namespace JsonUtil
}
template<class T>
- static void DeserializeVectorValues(vector<T> &v, const Json::Value &root)
+ static void DeserializeArrayValues(vector<T> &v, const Json::Value &root)
{
- v.resize( root.size() );
- for( unsigned i=0; i<v.size(); i++ )
- v[i] = root[i].asString();
+ v.clear();
+ for( unsigned i=0; i<root.size(); i++ )
+ {
+ T t;
+ if( root[i].TryGet( t ) )
+ v.push_back( t );
+ }
+ }
+
+ // don't pull in the set header here
+ template<typename S, typename T>
+ static void DeserializeArrayValuesIntoSet(S &s, const Json::Value &root)
+ {
+ s.clear();
+ for( unsigned i=0; i<root.size(); i++ )
+ {
+ T t;
+ if( root[i].TryGet( t ) )
+ s.insert( t );
+ }
+ }
+
+ template<typename T>
+ static void DeserializeArrayValuesIntoVector(vector<T> &v, const Json::Value &root)
+ {
+ v.clear();
+ for( unsigned i=0; i<root.size(); i++ )
+ {
+ T t;
+ if( root[i].TryGet( t ) )
+ v.push_back( t );
+ }
+ }
+
+ template <typename M>
+ static void DeserializeValueToValueMap(M &m, const Json::Value &root)
+ {
+ for( Json::Value::const_iterator iter = root.begin(); iter != root.end(); iter++ )
+ (*iter).TryGet( m[ iter.memberName() ] );
+ }
+
+ template <typename M, typename E, typename F>
+ static void DeserializeStringToValueMap(M &m, F fnToValue(E e), const Json::Value &root)
+ {
+ for( Json::Value::const_iterator iter = root.begin(); iter != root.end(); iter++ )
+ (*iter).TryGet( m[ fnToValue(iter.memberName()) ] );
+ }
+
+ template <typename M, typename E, typename F>
+ static void DeserializeStringToObjectMap(M &m, F fnToValue(E e), const Json::Value &root)
+ {
+ for( Json::Value::const_iterator iter = root.begin(); iter != root.end(); iter++ )
+ m[ fnToValue(iter.memberName()) ].Deserialize( *iter );
+ }
+
+ // Serialize a map that has a non-string key type
+ template <typename K, typename V>
+ static void DeserializeObjectToObjectMapAsArray(map<K,V> &m, const RString &sKeyName, const RString &sValueName, const Json::Value &root)
+ {
+ m.clear();
+ ASSERT( root.type() == Json::arrayValue );
+ for( Json::Value::const_iterator iter = root.begin(); iter != root.end(); iter++ )
+ {
+ ASSERT( (*iter).type() == Json::objectValue );
+ K k;
+ if( !k.Deserialize( (*iter)[sKeyName] ) )
+ continue;
+ V v;
+ if( !v.Deserialize( (*iter)[sValueName] ) )
+ continue;
+ m[k] = v;
+ }
+ }
+
+ template <typename K, typename V>
+ static void DeserializeObjectToValueMapAsArray(map<K,V> &m, const RString &sKeyName, const RString &sValueName, const Json::Value &root)
+ {
+ for( unsigned i=0; i<root.size(); i++ )
+ {
+ const Json::Value &root2 = root[i];
+ K k;
+ if( !k.Deserialize( root2[sKeyName] ) )
+ continue;
+ V v;
+ if( !root2[sValueName].TryGet(v) )
+ continue;
+ m[k] = v;
+ }
}
}
Modified: branches/4.0/stepmania/src/NotesLoaderJson.cpp
==============================================================================
--- branches/4.0/stepmania/src/NotesLoaderJson.cpp (original)
+++ branches/4.0/stepmania/src/NotesLoaderJson.cpp Wed Dec 29 14:08:42 2010
@@ -175,7 +175,7 @@ static void Deserialize( Song &out, cons
JsonUtil::DeserializeVectorObjects( vBgc, Deserialize, root["ForegroundChanges"] );
}
- JsonUtil::DeserializeVectorValues( out.m_vsKeysoundFile, root["KeySounds"] );
+ JsonUtil::DeserializeArrayValuesIntoVector( out.m_vsKeysoundFile, root["KeySounds"] );
{
vector<Steps*> vpSteps;
Modified: branches/4.0/stepmania/src/Profile.cpp
==============================================================================
--- branches/4.0/stepmania/src/Profile.cpp (original)
+++ branches/4.0/stepmania/src/Profile.cpp Wed Dec 29 14:08:42 2010
@@ -30,7 +30,6 @@
const RString STATS_XSL = "Stats.xsl";
const RString COMMON_XSL = "Common.xsl";
-const RString STATS_XML = "Stats.xml";
const RString STATS_JSON = "Stats.json";
const RString EDITABLE_INI = "Editable.ini";
const RString DONT_SHARE_SIG = "DontShare.sig";
@@ -41,10 +40,10 @@ const RString EDIT_COURSES_SUBDIR = "Ed
#define GUID_SIZE_BYTES 8
-#define MAX_EDITABLE_INI_SIZE_BYTES 2*1024 // 2KB
-#define MAX_PLAYER_STATS_XML_SIZE_BYTES \
- 100 /* Songs */ \
- * 3 /* Steps per Song */ \
+#define MAX_EDITABLE_INI_SIZE_BYTES 2*1024 // 2KB
+#define MAX_PLAYER_STATS_JSON_SIZE_BYTES \
+ 100 /* Songs */ \
+ * 3 /* Steps per Song */ \
* 10 /* HighScores per Steps */ \
* 1024 /* size in bytes of a HighScores XNode */
@@ -127,16 +126,13 @@ void Profile::InitGeneralData()
m_iTotalMines = 0;
m_iTotalHands = 0;
- FOREACH_PlayMode( i )
- m_iNumSongsPlayedByPlayMode[i] = 0;
+ m_iNumSongsPlayedByPlayMode.clear();
m_iNumSongsPlayedByStyle.clear();
- FOREACH_Difficulty( i )
- m_iNumSongsPlayedByDifficulty[i] = 0;
- for( int i=0; i<MAX_METER+1; i++ )
- m_iNumSongsPlayedByMeter[i] = 0;
+ m_iNumSongsPlayedByDifficulty.clear();
+ m_iNumSongsPlayedByMeter.clear();
m_iNumTotalSongsPlayed = 0;
- ZERO( m_iNumStagesPassedByPlayMode );
- ZERO( m_iNumStagesPassedByGrade );
+ m_iNumStagesPassedByPlayMode.clear();
+ m_iNumStagesPassedByGrade.clear();
Lua *L = LUA->Get();
lua_newtable( L );
@@ -234,8 +230,8 @@ float Profile::GetCaloriesBurnedToday()
int Profile::GetTotalNumSongsPassed() const
{
int iTotal = 0;
- FOREACH_PlayMode( i )
- iTotal += m_iNumStagesPassedByPlayMode[i];
+ FOREACHM_CONST( PlayMode, int, m_iNumStagesPassedByPlayMode, iter )
+ iTotal += iter->second;
return iTotal;
}
@@ -786,10 +782,6 @@ void Profile::IncrementCategoryPlayCount
#define WARN_AND_RETURN_M(m) { WARN_M(m); return; }
#define WARN_AND_CONTINUE_M(m) { WARN_M(m); continue; }
#define WARN_AND_BREAK_M(m) { WARN_M(m); break; }
-#define LOAD_NODE(X) { \
- const XNode* X = xml->GetChild(#X); \
- if( X==NULL ) LOG->Warn("Failed to read section " #X); \
- else Load##X##FromNode(X); }
ProfileLoadResult Profile::LoadAllFromDir( RString sDir, bool bRequireSignature )
{
@@ -805,7 +797,7 @@ ProfileLoadResult Profile::LoadAllFromDi
LoadEditableDataFromDir( sDir );
// Check for the existance of stats.xml
- RString fn = sDir + STATS_XML;
+ RString fn = sDir + STATS_JSON;
if( !IsAFile(fn) )
return ProfileLoadResult_FailedNoProfile;
@@ -815,7 +807,7 @@ ProfileLoadResult Profile::LoadAllFromDi
if( !IsMachine() ) // only check stats coming from the player
{
int iBytes = FILEMAN->GetFileSizeInBytes( fn );
- if( iBytes > MAX_PLAYER_STATS_XML_SIZE_BYTES )
+ if( iBytes > MAX_PLAYER_STATS_JSON_SIZE_BYTES )
{
LOG->Warn( "The file '%s' is unreasonably large. It won't be loaded.", fn.c_str() );
return ProfileLoadResult_FailedTampered;
@@ -847,27 +839,27 @@ ProfileLoadResult Profile::LoadAllFromDi
}
LOG->Trace( "Loading %s", fn.c_str() );
- XNode xml;
- if( !XmlFileUtil::LoadFromFileShowErrors(xml, fn) )
+ Json::Value root;
+ if( !JsonUtil::LoadFromFileShowErrors(root, fn) )
return ProfileLoadResult_FailedTampered;
LOG->Trace( "Done." );
- return LoadStatsXmlFromNode( &xml );
+ return LoadStatsJson( root );
}
-ProfileLoadResult Profile::LoadStatsXmlFromNode( const XNode *xml, bool bIgnoreEditable )
+RString DateTimeToString( const DateTime &dt )
{
- /* The placeholder stats.xml file has an <html> tag. Don't load it, but don't
- * warn about it. */
- if( xml->m_sName == "html" )
- return ProfileLoadResult_FailedNoProfile;
-
- if( xml->m_sName != "Stats" )
- {
- WARN_M( xml->m_sName );
- return ProfileLoadResult_FailedTampered;
- }
+ return dt.GetString();
+}
+DateTime StringToDateTime( const RString &s )
+{
+ DateTime dt;
+ dt.FromString(s);
+ return dt;
+}
+ProfileLoadResult Profile::LoadStatsJson( const Json::Value &root, bool bIgnoreEditable )
+{
/* These are loaded from Editable, so we usually want to ignore them
* here. */
RString sName = m_sDisplayName;
@@ -875,14 +867,14 @@ ProfileLoadResult Profile::LoadStatsXmlF
RString sLastUsedHighScoreName = m_sLastUsedHighScoreName;
int iWeightPounds = m_iWeightPounds;
- LOAD_NODE( GeneralData );
- LOAD_NODE( SongScores );
- LOAD_NODE( CourseScores );
- LOAD_NODE( CategoryScores );
- LOAD_NODE( ScreenshotData );
- LOAD_NODE( CalorieData );
- LOAD_NODE( RecentSongScores );
- LOAD_NODE( RecentCourseScores );
+ LoadGeneral( root["General"] );
+ JsonUtil::DeserializeObjectToObjectMapAsArray( m_SongHighScores, "Song", "HighScoresForASong", root["SongScores"] );
+ JsonUtil::DeserializeObjectToObjectMapAsArray( m_CourseHighScores, "Course", "HighScoresForACourse", root["CourseScores"] );
+ JsonUtil::DeserializeStringToObjectMap( m_CategoryHighScores, StringToStepsType, root["CategoryScores"] );
+ JsonUtil::DeserializeArrayObjects( m_vScreenshots, root["ScreenshotData"] );
+ JsonUtil::DeserializeStringToValueMap( m_mapDayToCaloriesBurned, StringToDateTime, root["CalorieData"] );
+ JsonUtil::DeserializeArrayObjects( m_vRecentStepsScores, root["RecentSongScores"] );
+ JsonUtil::DeserializeArrayObjects( m_vRecentCourseScores, root["RecentCourseScores"] );
if( bIgnoreEditable )
{
@@ -920,31 +912,24 @@ bool Profile::SaveAllToDir( RString sDir
void Profile::RankingCategoryToHighScoreList::Serialize( Json::Value &root ) const
{
- JsonUtil::SerializeEnumToObjectMap( m_v, RankingCategoryToString, root );
+ JsonUtil::SerializeStringToObjectMap( m_v, RankingCategoryToString, root );
}
void Profile::RankingCategoryToHighScoreList::Deserialize( const Json::Value &root )
{
- FAIL_M("unfinished");
+ JsonUtil::DeserializeStringToObjectMap( m_v, StringToRankingCategory, root );
}
bool Profile::SaveStatsJsonToDir( RString sDir, bool bSignData ) const
{
Json::Value root;
SaveGeneral( root["General"] );
-
- JsonUtil::SerializeMapAsArray( m_SongHighScores, "Song", "HighScoresForASong", root["SongScores"] );
-
- JsonUtil::SerializeMapAsArray( m_CourseHighScores, "Course", "HighScoresForACourse", root["CourseScores"] );
-
- JsonUtil::SerializeEnumToObjectMap( m_CategoryHighScores, StepsTypeToString, root["CategoryScores"] );
-
+ JsonUtil::SerializeObjectToObjectMapAsArray( m_SongHighScores, "Song", "HighScoresForASong", root["SongScores"] );
+ JsonUtil::SerializeObjectToObjectMapAsArray( m_CourseHighScores, "Course", "HighScoresForACourse", root["CourseScores"] );
+ JsonUtil::SerializeStringToObjectMap( m_CategoryHighScores, StepsTypeToString, root["CategoryScores"] );
JsonUtil::SerializeArrayObjects( m_vScreenshots, root["ScreenshotData"] );
-
- JsonUtil::SerializeValueToValueMap( m_mapDayToCaloriesBurned, root["CalorieData"] );
-
+ JsonUtil::SerializeStringToValueMap( m_mapDayToCaloriesBurned, DateTimeToString, root["CalorieData"] );
JsonUtil::SerializeArrayObjects( m_vRecentStepsScores, root["RecentSongScores"] );
-
JsonUtil::SerializeArrayObjects( m_vRecentCourseScores, root["RecentCourseScores"] );
RString fn = sDir + STATS_JSON;
@@ -981,6 +966,16 @@ void Profile::SaveEditableDataToDir( RSt
ini.WriteFile( sDir + EDITABLE_INI );
}
+const RString MeterToString(int i)
+{
+ return ssprintf("%d",i);
+}
+
+int StringToMeter(const RString &s)
+{
+ return atoi(s);
+}
+
void Profile::SaveGeneral( Json::Value &root ) const
{
// These are write-only elements that are normally never read again.
@@ -1019,89 +1014,17 @@ void Profile::SaveGeneral( Json::Value &
root["TotalRolls"] = m_iTotalRolls;
root["TotalMines"] = m_iTotalMines;
root["TotalHands"] = m_iTotalHands;
- root["Data"] = m_SavedLuaData.Serialize();
+ root["SavedLuaData"] = m_SavedLuaData.Serialize();
root["NumTotalSongsPlayed"] = m_iNumTotalSongsPlayed;
- // Keep declared variables in a very local scope so they aren't accidentally used where they're
- // not intended. There's a lot of copying and pasting in this code.
-
- {
- Json::Value &v = root["DefaultModifiersByGame"];
- FOREACHM_CONST( RString, RString, m_DefaultModifiersByGame, it )
- v[ it->first ] = it->second;
- }
-
- {
- JsonUtil::SerializeArrayValues( m_UnlockedEntryIDs, root["UnlockEntryIDs"] );
- }
-
- {
- Json::Value &v = root["NumSongsPlayedByPlayMode"];
- FOREACH_PlayMode( pm )
- {
- /* Don't save unplayed PlayModes. */
- if( !m_iNumSongsPlayedByPlayMode[pm] )
- continue;
- v[PlayModeToString(pm)] = m_iNumSongsPlayedByPlayMode[pm];
- }
- }
-
- {
- Json::Value &v = root["NumSongsPlayedByStyle"];
- v = Json::Value( Json::arrayValue );
- v.resize( m_iNumSongsPlayedByStyle.size() );
- int i=0;
- FOREACHM_CONST( StyleID, int, m_iNumSongsPlayedByStyle, iter )
- {
- const StyleID &s = iter->first;
- int iNumPlays = iter->second;
-
- Json::Value &v2 = v[i++];
- s.Serialize( v2["Style"] );
- v2["NumPlays"] = iNumPlays;
- }
- }
-
- {
- Json::Value &v = root["NumSongsPlayedByDifficulty"];
- FOREACH_Difficulty( dc )
- {
- if( !m_iNumSongsPlayedByDifficulty[dc] )
- continue;
- v[ DifficultyToString(dc) ] = m_iNumSongsPlayedByDifficulty[dc];
- }
- }
-
- {
- Json::Value &v = root["NumSongsPlayedByMeter"];
- for( int i=0; i<MAX_METER+1; i++ )
- {
- if( !m_iNumSongsPlayedByMeter[i] )
- continue;
- v[ ssprintf("%d",i) ] = m_iNumSongsPlayedByMeter[i];
- }
- }
-
- {
- Json::Value &v = root["NumStagesPassedByPlayMode"];
- FOREACH_PlayMode( pm )
- {
- /* Don't save unplayed PlayModes. */
- if( !m_iNumStagesPassedByPlayMode[pm] )
- continue;
- v[ PlayModeToString(pm) ] = m_iNumStagesPassedByPlayMode[pm];
- }
- }
-
- {
- Json::Value &v = root["NumStagesPassedByGrade"];
- FOREACH_Grade( g )
- {
- if( !m_iNumStagesPassedByGrade[g] )
- continue;
- v[ GradeToString(g) ] = m_iNumStagesPassedByGrade[g];
- }
- }
+ JsonUtil::SerializeValueToValueMap( m_DefaultModifiersByGame, root["DefaultModifiersByGame"] );
+ JsonUtil::SerializeArrayValues( m_UnlockedEntryIDs, root["UnlockEntryIDs"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByPlayMode, PlayModeToString, root["NumSongsPlayedByPlayMode"] );
+ JsonUtil::SerializeObjectToValueMapAsArray(m_iNumSongsPlayedByStyle, "Style", "NumPlays", root["NumSongsPlayedByStyle"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByDifficulty, DifficultyToString, root["NumSongsPlayedByDifficulty"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumSongsPlayedByMeter, MeterToString, root["NumSongsPlayedByMeter"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumStagesPassedByPlayMode, PlayModeToString, root["NumStagesPassedByPlayMode"] );
+ JsonUtil::SerializeStringToValueMap( m_iNumStagesPassedByGrade, GradeToString, root["NumStagesPassedByGrade"] );
}
ProfileLoadResult Profile::LoadEditableDataFromDir( RString sDir )
@@ -1141,142 +1064,60 @@ ProfileLoadResult Profile::LoadEditableD
return ProfileLoadResult_Success;
}
-void Profile::LoadGeneralDataFromNode( const XNode* pNode )
+void Profile::LoadGeneral( const Json::Value &root )
{
- ASSERT( pNode->m_sName == "GeneralData" );
-
- RString s;
- const XNode* pTemp;
-
- pNode->GetChildValue( "DisplayName", m_sDisplayName );
- pNode->GetChildValue( "CharacterID", m_sCharacterID );
- pNode->GetChildValue( "LastUsedHighScoreName", m_sLastUsedHighScoreName );
- pNode->GetChildValue( "WeightPounds", m_iWeightPounds );
- pNode->GetChildValue( "Guid", m_sGuid );
- pNode->GetChildValue( "SortOrder", s ); m_SortOrder = StringToSortOrder( s );
- pNode->GetChildValue( "LastDifficulty", s ); m_LastDifficulty = StringToDifficulty( s );
- pNode->GetChildValue( "LastCourseDifficulty", s ); m_LastCourseDifficulty = StringToCourseDifficulty( s );
- pTemp = pNode->GetChild( "Song" ); if( pTemp ) m_lastSong.LoadFromNode( pTemp );
- pTemp = pNode->GetChild( "Course" ); if( pTemp ) m_lastCourse.LoadFromNode( pTemp );
- pNode->GetChildValue( "TotalPlays", m_iTotalPlays );
- pNode->GetChildValue( "TotalPlaySeconds", m_iTotalPlaySeconds );
- pNode->GetChildValue( "TotalGameplaySeconds", m_iTotalGameplaySeconds );
- pNode->GetChildValue( "CurrentCombo", m_iCurrentCombo );
- pNode->GetChildValue( "TotalCaloriesBurned", m_fTotalCaloriesBurned );
- pNode->GetChildValue( "GoalType", (int&)m_GoalType );
- pNode->GetChildValue( "GoalCalories", m_iGoalCalories );
- pNode->GetChildValue( "GoalSeconds", m_iGoalSeconds );
- pNode->GetChildValue( "LastPlayedMachineGuid", m_sLastPlayedMachineGuid );
- pNode->GetChildValue( "LastPlayedDate", m_LastPlayedDate );
- pNode->GetChildValue( "TotalDancePoints", m_iTotalDancePoints );
- pNode->GetChildValue( "NumExtraStagesPassed", m_iNumExtraStagesPassed );
- pNode->GetChildValue( "NumExtraStagesFailed", m_iNumExtraStagesFailed );
- pNode->GetChildValue( "NumToasties", m_iNumToasties );
- pNode->GetChildValue( "TotalTapsAndHolds", m_iTotalTapsAndHolds );
- pNode->GetChildValue( "TotalJumps", m_iTotalJumps );
- pNode->GetChildValue( "TotalHolds", m_iTotalHolds );
- pNode->GetChildValue( "TotalRolls", m_iTotalRolls );
- pNode->GetChildValue( "TotalMines", m_iTotalMines );
- pNode->GetChildValue( "TotalHands", m_iTotalHands );
-
- {
- RString sData;
- if( pNode->GetChildValue( "Data", sData ) )
- {
- m_SavedLuaData.LoadFromString( sData );
- if( m_SavedLuaData.GetLuaType() != LUA_TTABLE )
- {
- LOG->Warn( "Profile data did not evaluate to a table" );
- Lua *L = LUA->Get();
- lua_newtable( L );
- m_SavedLuaData.SetFromStack( L );
- LUA->Release( L );
- }
- }
- }
-
- {
- const XNode* pDefaultModifiers = pNode->GetChild("DefaultModifiers");
- if( pDefaultModifiers )
- {
- FOREACH_CONST_Child( pDefaultModifiers, game_type )
- {
- m_DefaultModifiersByGame[game_type->m_sName] = game_type->m_sValue;
- }
- }
- }
-
- {
- const XNode* pUnlocks = pNode->GetChild("Unlocks");
- if( pUnlocks )
- {
- FOREACH_CONST_Child( pUnlocks, unlock )
- {
- RString sUnlockEntryID;
- if( unlock->GetAttrValue("UnlockEntryID",sUnlockEntryID) )
- m_UnlockedEntryIDs.insert( sUnlockEntryID );
- }
- }
- }
-
- {
- const XNode* pNumSongsPlayedByPlayMode = pNode->GetChild("NumSongsPlayedByPlayMode");
- if( pNumSongsPlayedByPlayMode )
- FOREACH_PlayMode( pm )
- pNumSongsPlayedByPlayMode->GetChildValue( PlayModeToString(pm), m_iNumSongsPlayedByPlayMode[pm] );
- }
-
- {
- const XNode* pNumSongsPlayedByStyle = pNode->GetChild("NumSongsPlayedByStyle");
- if( pNumSongsPlayedByStyle )
- {
- FOREACH_CONST_Child( pNumSongsPlayedByStyle, style )
- {
- if( style->m_sName != "Style" )
- continue;
-
- StyleID s;
- s.LoadFromNode( style );
-
- if( !s.IsValid() )
- WARN_AND_CONTINUE;
-
- style->GetValue( m_iNumSongsPlayedByStyle[s] );
- }
+ root["DisplayName"].TryGet( m_sDisplayName );
+ root["CharacterID"].TryGet( m_sCharacterID );
+ root["LastUsedHighScoreName"].TryGet( m_sLastUsedHighScoreName );
+ root["WeightPounds"].TryGet( m_iWeightPounds );
+ root["Guid"].TryGet( m_sGuid );
+ m_SortOrder = StringToSortOrder( root["SortOrder"].asString() );
+ m_LastDifficulty = StringToDifficulty( root["LastDifficulty"].asString() );
+ m_LastCourseDifficulty = StringToCourseDifficulty( root["LastCourseDifficulty"].asString() );
+ m_lastSong.Deserialize( root["LastSong"] );
+ m_lastCourse.Deserialize( root["LastCourse"] );
+ root["TotalPlays"].TryGet( m_iTotalPlays );
+ root["TotalPlaySeconds"].TryGet( m_iTotalPlaySeconds );
+ root["TotalGameplaySeconds"].TryGet( m_iTotalGameplaySeconds );
+ root["CurrentCombo"].TryGet( m_iCurrentCombo );
+ root["TotalCaloriesBurned"].TryGet( m_fTotalCaloriesBurned );
+ root["GoalType"].TryGet( (int&)m_GoalType );
+ root["GoalCalories"].TryGet( m_iGoalCalories );
+ root["GoalSeconds"].TryGet( m_iGoalSeconds );
+ root["LastPlayedMachineGuid"].TryGet( m_sLastPlayedMachineGuid );
+ m_LastPlayedDate.FromString( root["LastPlayedDate"].asString() );
+ root["TotalDancePoints"].TryGet( m_iTotalDancePoints );
+ root["NumExtraStagesPassed"].TryGet( m_iNumExtraStagesPassed );
+ root["NumExtraStagesFailed"].TryGet( m_iNumExtraStagesFailed );
+ root["NumToasties"].TryGet( m_iNumToasties );
+ root["TotalTapsAndHolds"].TryGet( m_iTotalTapsAndHolds );
+ root["TotalJumps"].TryGet( m_iTotalJumps );
+ root["TotalHolds"].TryGet( m_iTotalHolds );
+ root["TotalRolls"].TryGet( m_iTotalRolls );
+ root["TotalMines"].TryGet( m_iTotalMines );
+ root["TotalHands"].TryGet( m_iTotalHands );
+ root["NumTotalSongsPlayed"].TryGet( m_iNumTotalSongsPlayed );
+
+ {
+ m_SavedLuaData.LoadFromString( root["SavedLuaData"].asString() );
+ if( m_SavedLuaData.GetLuaType() != LUA_TTABLE )
+ {
+ LOG->Warn( "Profile data did not evaluate to a table" );
+ Lua *L = LUA->Get();
+ lua_newtable( L );
+ m_SavedLuaData.SetFromStack( L );
+ LUA->Release( L );
}
}
- {
- const XNode* pNumSongsPlayedByDifficulty = pNode->GetChild("NumSongsPlayedByDifficulty");
- if( pNumSongsPlayedByDifficulty )
- FOREACH_Difficulty( dc )
- pNumSongsPlayedByDifficulty->GetChildValue( DifficultyToString(dc), m_iNumSongsPlayedByDifficulty[dc] );
- }
-
- {
- const XNode* pNumSongsPlayedByMeter = pNode->GetChild("NumSongsPlayedByMeter");
- if( pNumSongsPlayedByMeter )
- for( int i=0; i<MAX_METER+1; i++ )
- pNumSongsPlayedByMeter->GetChildValue( ssprintf("%d",i), m_iNumSongsPlayedByMeter[i] );
- }
-
- pNode->GetChildValue("NumTotalSongsPlayed", m_iNumTotalSongsPlayed );
-
- {
- const XNode* pNumStagesPassedByGrade = pNode->GetChild("NumStagesPassedByGrade");
- if( pNumStagesPassedByGrade )
- FOREACH_Grade( g )
- pNumStagesPassedByGrade->GetChildValue( GradeToString(g), m_iNumStagesPassedByGrade[g] );
- }
-
- {
- const XNode* pNumStagesPassedByPlayMode = pNode->GetChild("NumStagesPassedByPlayMode");
- if( pNumStagesPassedByPlayMode )
- FOREACH_PlayMode( pm )
- pNumStagesPassedByPlayMode->GetChildValue( PlayModeToString(pm), m_iNumStagesPassedByPlayMode[pm] );
-
- }
-
+ JsonUtil::DeserializeValueToValueMap( m_DefaultModifiersByGame, root["DefaultModifiersByGame"] );
+ JsonUtil::DeserializeArrayValuesIntoSet<set<RString>, RString>( m_UnlockedEntryIDs, root["UnlockedEntryID"] );
+ JsonUtil::DeserializeStringToValueMap( m_iNumSongsPlayedByPlayMode, StringToPlayMode, root["NumSongsPlayedByPlayMode"] );
+ JsonUtil::DeserializeObjectToValueMapAsArray( m_iNumSongsPlayedByStyle, "Style", "NumPlays", root["NumSongsPlayedByStyle"] );
+ JsonUtil::DeserializeStringToValueMap( m_iNumSongsPlayedByDifficulty, StringToDifficulty, root["NumSongsPlayedByDifficulty"] );
+ JsonUtil::DeserializeStringToValueMap( m_iNumSongsPlayedByMeter, StringToMeter, root["NumSongsPlayedByMeter"] );
+ JsonUtil::DeserializeStringToValueMap( m_iNumStagesPassedByPlayMode, StringToPlayMode, root["NumStagesPassedByPlayMode"] );
+ JsonUtil::DeserializeStringToValueMap( m_iNumStagesPassedByGrade, StringToGrade, root["NumStagesPassedByGrade"] );
}
void Profile::AddStepTotals( int iTotalTapsAndHolds, int iTotalJumps, int iTotalHolds, int iTotalRolls, int iTotalMines, int iTotalHands, float fCaloriesBurned )
@@ -1296,179 +1137,24 @@ void Profile::AddStepTotals( int iTotalT
void Profile::HighScoresForASong::Serialize( Json::Value &root ) const
{
- JsonUtil::SerializeMapAsArray( m_StepsHighScores, "Steps", "HighScoreList", root );
-}
-
-void Profile::HighScoresForASong::Deserialize( const Json::Value &root )
-{
- FAIL_M("unfinished");
+ JsonUtil::SerializeObjectToObjectMapAsArray( m_StepsHighScores, "Steps", "HighScoreList", root );
}
-void Profile::SaveSongScores( Json::Value &root ) const
+bool Profile::HighScoresForASong::Deserialize( const Json::Value &root )
{
- CHECKPOINT;
- ASSERT( this );
-}
-
-void Profile::LoadSongScoresFromNode( const XNode* pSongScores )
-{
- CHECKPOINT;
-
- ASSERT( pSongScores->m_sName == "SongScores" );
-
- FOREACH_CONST_Child( pSongScores, pSong )
- {
- if( pSong->m_sName != "Song" )
- continue;
-
- SongID songID;
- songID.LoadFromNode( pSong );
- if( !songID.IsValid() )
- WARN_AND_CONTINUE;
-
- FOREACH_CONST_Child( pSong, pSteps )
- {
- if( pSteps->m_sName != "Steps" )
- continue;
-
- StepsID stepsID;
- stepsID.LoadFromNode( pSteps );
- if( !stepsID.IsValid() )
- WARN_AND_CONTINUE;
-
- const XNode *pHighScoreListNode = pSteps->GetChild("HighScoreList");
- if( pHighScoreListNode == NULL )
- WARN_AND_CONTINUE;
-
- HighScoreList &hsl = m_SongHighScores[songID].m_StepsHighScores[stepsID];
- hsl.LoadFromNode( pHighScoreListNode );
- }
- }
+ JsonUtil::DeserializeObjectToObjectMapAsArray( m_StepsHighScores, "Steps", "HighScoreList", root );
+ return true;
}
void Profile::HighScoresForACourse::Serialize( Json::Value &root ) const
{
- JsonUtil::SerializeMapAsArray( m_TrailHighScores, "Trail", "HighScoreList", root );
-}
-
-void Profile::SaveCourseScores( Json::Value &root ) const
-{
- CHECKPOINT;
- ASSERT( this );
-}
-
-void Profile::LoadCourseScoresFromNode( const XNode* pCourseScores )
-{
- CHECKPOINT;
-
- ASSERT( pCourseScores->m_sName == "CourseScores" );
-
- vector<Course*> vpAllCourses;
- SONGMAN->GetAllCourses( vpAllCourses, true );
-
- FOREACH_CONST_Child( pCourseScores, pCourse )
- {
- if( pCourse->m_sName != "Course" )
- continue;
-
- CourseID courseID;
- courseID.LoadFromNode( pCourse );
- if( !courseID.IsValid() )
- WARN_AND_CONTINUE;
-
-
- // Backward compatability hack to fix importing scores of old style
- // courses that weren't in group folder but have now been moved into
- // a group folder:
- // If the courseID doesn't resolve, then take the file name part of sPath
- // and search for matches of just the file name.
- {
- Course *pC = courseID.ToCourse();
- if( pC == NULL )
- {
- RString sDir, sFName, sExt;
- splitpath( courseID.sPath, sDir, sFName, sExt );
- RString sFullFileName = sFName + sExt;
-
- FOREACH_CONST( Course*, vpAllCourses, c )
- {
- RString sOther = (*c)->m_sPath.Right(sFullFileName.size());
-
- if( sFullFileName.CompareNoCase(sOther) == 0 )
- {
- pC = *c;
- courseID.FromCourse( pC );
- break;
- }
- }
- }
- }
-
-
- FOREACH_CONST_Child( pCourse, pTrail )
- {
- if( pTrail->m_sName != "Trail" )
- continue;
-
- TrailID trailID;
- trailID.LoadFromNode( pTrail );
- if( !trailID.IsValid() )
- WARN_AND_CONTINUE;
-
- const XNode *pHighScoreListNode = pTrail->GetChild("HighScoreList");
- if( pHighScoreListNode == NULL )
- WARN_AND_CONTINUE;
-
- HighScoreList &hsl = m_CourseHighScores[courseID].m_TrailHighScores[trailID];
- hsl.LoadFromNode( pHighScoreListNode );
- }
- }
-}
-
-void Profile::SaveCategoryScores( Json::Value &root ) const
-{
- CHECKPOINT;
- ASSERT( this );
-
+ JsonUtil::SerializeObjectToObjectMapAsArray( m_TrailHighScores, "Trail", "HighScoreList", root );
}
-void Profile::LoadCategoryScoresFromNode( const XNode* pCategoryScores )
+bool Profile::HighScoresForACourse::Deserialize( const Json::Value &root )
{
- CHECKPOINT;
-
- ASSERT( pCategoryScores->m_sName == "CategoryScores" );
-
- FOREACH_CONST_Child( pCategoryScores, pStepsType )
- {
- if( pStepsType->m_sName != "StepsType" )
- continue;
-
- RString str;
- if( !pStepsType->GetAttrValue( "Type", str ) )
- WARN_AND_CONTINUE;
- StepsType st = GameManager::StringToStepsType( str );
- if( st == STEPS_TYPE_INVALID )
- WARN_AND_CONTINUE_M( str );
-
- FOREACH_CONST_Child( pStepsType, pRadarCategory )
- {
- if( pRadarCategory->m_sName != "RankingCategory" )
- continue;
-
- if( !pRadarCategory->GetAttrValue( "Type", str ) )
- WARN_AND_CONTINUE;
- RankingCategory rc = StringToRankingCategory( str );
- if( rc == RANKING_INVALID )
- WARN_AND_CONTINUE_M( str );
-
- const XNode *pHighScoreListNode = pRadarCategory->GetChild("HighScoreList");
- if( pHighScoreListNode == NULL )
- WARN_AND_CONTINUE;
-
- HighScoreList &hsl = this->GetCategoryHighScoreList( st, rc );
- hsl.LoadFromNode( pHighScoreListNode );
- }
- }
+ JsonUtil::DeserializeObjectToObjectMapAsArray( m_TrailHighScores, "Trail", "HighScoreList", root );
+ return true;
}
void Profile::SaveStatsWebPageToDir( RString sDir ) const
@@ -1492,61 +1178,6 @@ void Profile::AddScreenshot( const Scree
m_vScreenshots.push_back( screenshot );
}
-void Profile::LoadScreenshotDataFromNode( const XNode* pScreenshotData )
-{
- CHECKPOINT;
-
- ASSERT( pScreenshotData->m_sName == "ScreenshotData" );
- FOREACH_CONST_Child( pScreenshotData, pScreenshot )
- {
- if( pScreenshot->m_sName != "Screenshot" )
- WARN_AND_CONTINUE_M( pScreenshot->m_sName );
-
- Screenshot ss;
- ss.LoadFromNode( pScreenshot );
-
- m_vScreenshots.push_back( ss );
- }
-}
-
-
-void Profile::SaveScreenshotData( Json::Value &root ) const
-{
- CHECKPOINT;
-}
-
-void Profile::LoadCalorieDataFromNode( const XNode* pCalorieData )
-{
- CHECKPOINT;
-
- ASSERT( pCalorieData->m_sName == "CalorieData" );
- FOREACH_CONST_Child( pCalorieData, pCaloriesBurned )
- {
- if( pCaloriesBurned->m_sName != "CaloriesBurned" )
- WARN_AND_CONTINUE_M( pCaloriesBurned->m_sName );
-
- RString sDate;
- if( !pCaloriesBurned->GetAttrValue("Date",sDate) )
- WARN_AND_CONTINUE;
- DateTime date;
- if( !date.FromString(sDate) )
- WARN_AND_CONTINUE_M( sDate );
-
- float fCaloriesBurned = 0;
-
- pCaloriesBurned->GetValue(fCaloriesBurned);
-
- m_mapDayToCaloriesBurned[date] = fCaloriesBurned;
- }
-}
-
-void Profile::SaveCalorieData( Json::Value &root ) const
-{
- CHECKPOINT;
- ASSERT( this );
-
-}
-
float Profile::GetCaloriesBurnedForDay( DateTime day ) const
{
day.StripTime();
@@ -1597,33 +1228,6 @@ void Profile::HighScoreForASongAndSteps:
hs.Deserialize( root["HighScore"] );
}
-void Profile::LoadRecentSongScoresFromNode( const XNode* pRecentSongScores )
-{
- CHECKPOINT;
-
- ASSERT( pRecentSongScores->m_sName == "RecentSongScores" );
- FOREACH_CONST_Child( pRecentSongScores, p )
- {
- if( p->m_sName == "HighScoreForASongAndSteps" )
- {
- HighScoreForASongAndSteps h;
- h.LoadFromNode( p );
-
- m_vRecentStepsScores.push_back( h );
- }
- else
- {
- WARN_AND_CONTINUE_M( p->m_sName );
- }
- }
-}
-
-void Profile::SaveRecentSongScores( Json::Value &root ) const
-{
- CHECKPOINT;
- ASSERT( this );
-}
-
void Profile::AddStepsRecentScore( const Song* pSong, const Steps* pSteps, HighScore hs )
{
HighScoreForASongAndSteps h;
@@ -1679,33 +1283,6 @@ void Profile::HighScoreForACourseAndTrai
hs.Deserialize( root["HighScore"] );
}
-void Profile::LoadRecentCourseScoresFromNode( const XNode* pRecentCourseScores )
-{
- CHECKPOINT;
-
- ASSERT( pRecentCourseScores->m_sName == "RecentCourseScores" );
- FOREACH_CONST_Child( pRecentCourseScores, p )
- {
- if( p->m_sName == "HighScoreForACourseAndTrail" )
- {
- HighScoreForACourseAndTrail h;
- h.LoadFromNode( p );
-
- m_vRecentCourseScores.push_back( h );
- }
- else
- {
- WARN_AND_CONTINUE_M( p->m_sName );
- }
- }
-}
-
-void Profile::SaveRecentCourseScores( Json::Value &root ) const
-{
- CHECKPOINT;
- ASSERT( this );
-}
-
void Profile::AddCourseRecentScore( const Course* pCourse, const Trail* pTrail, HighScore hs )
{
HighScoreForACourseAndTrail h;
@@ -1754,10 +1331,10 @@ bool Profile::IsMachine() const
void Profile::MoveBackupToDir( RString sFromDir, RString sToDir )
{
- FILEMAN->Move( sFromDir+EDITABLE_INI, sToDir+EDITABLE_INI );
- FILEMAN->Move( sFromDir+STATS_XML, sToDir+STATS_XML );
- FILEMAN->Move( sFromDir+STATS_XML+SIGNATURE_APPEND, sToDir+STATS_XML+SIGNATURE_APPEND );
- FILEMAN->Move( sFromDir+DONT_SHARE_SIG, sToDir+DONT_SHARE_SIG );
+ FILEMAN->Move( sFromDir+EDITABLE_INI, sToDir+EDITABLE_INI );
+ FILEMAN->Move( sFromDir+STATS_JSON, sToDir+STATS_JSON );
+ FILEMAN->Move( sFromDir+STATS_JSON+SIGNATURE_APPEND, sToDir+STATS_JSON+SIGNATURE_APPEND );
+ FILEMAN->Move( sFromDir+DONT_SHARE_SIG, sToDir+DONT_SHARE_SIG );
}
// lua start
Modified: branches/4.0/stepmania/src/Profile.h
==============================================================================
--- branches/4.0/stepmania/src/Profile.h (original)
+++ branches/4.0/stepmania/src/Profile.h Wed Dec 29 14:08:42 2010
@@ -25,7 +25,7 @@ namespace Json { class Value; }
//
// Current file versions
//
-extern const RString STATS_XML;
+extern const RString STATS_JSON;
extern const RString EDITABLE_INI;
@@ -138,14 +138,29 @@ public:
mutable DateTime m_LastPlayedDate;
/* These stats count twice in the machine profile if two players are playing;
* that's the only approach that makes sense for ByDifficulty and ByMeter. */
- int m_iNumSongsPlayedByPlayMode[NUM_PlayMode];
+ map<PlayMode,int> m_iNumSongsPlayedByPlayMode;
+ int GetNumSongsPlayedByPlayMode(PlayMode i) const
+ {
+ map<PlayMode,int>::const_iterator iter = m_iNumSongsPlayedByPlayMode.find(i);
+ if( iter == m_iNumSongsPlayedByPlayMode.end() )
+ return 0;
+ return iter->second;
+ }
map<StyleID,int> m_iNumSongsPlayedByStyle;
- int m_iNumSongsPlayedByDifficulty[NUM_Difficulty];
- int m_iNumSongsPlayedByMeter[MAX_METER+1];
+ map<Difficulty,int> m_iNumSongsPlayedByDifficulty;
+ map<int,int> m_iNumSongsPlayedByMeter;
/* This stat counts once per song, even if two players are active. */
int m_iNumTotalSongsPlayed;
- int m_iNumStagesPassedByPlayMode[NUM_PlayMode];
- int m_iNumStagesPassedByGrade[NUM_Grade];
+ map<PlayMode,int> m_iNumStagesPassedByPlayMode;
+ map<Grade,int> m_iNumStagesPassedByGrade;
+ int GetNumStagesPassedByGrade(Grade i) const
+ {
+ map<Grade,int>::const_iterator iter = m_iNumStagesPassedByGrade.find(i);
+ if( iter == m_iNumStagesPassedByGrade.end() )
+ return 0;
+ return iter->second;
+ }
+
//
// Song high scores
@@ -156,7 +171,7 @@ public:
int GetNumTimesPlayed() const;
void Serialize( Json::Value &root ) const;
- void Deserialize( const Json::Value &root );
+ bool Deserialize( const Json::Value &root );
};
std::map<SongID,HighScoresForASong> m_SongHighScores;
@@ -181,7 +196,7 @@ public:
int GetNumTimesPlayed() const;
void Serialize( Json::Value &root ) const;
- void Deserialize( const Json::Value &root );
+ bool Deserialize( const Json::Value &root );
};
map<CourseID,HighScoresForACourse> m_CourseHighScores;
@@ -311,26 +326,12 @@ public:
bool SaveAllToDir( RString sDir, bool bSignData ) const;
ProfileLoadResult LoadEditableDataFromDir( RString sDir );
- ProfileLoadResult LoadStatsXmlFromNode( const XNode* pNode, bool bIgnoreEditable = true );
- void LoadGeneralDataFromNode( const XNode* pNode );
- void LoadSongScoresFromNode( const XNode* pNode );
- void LoadCourseScoresFromNode( const XNode* pNode );
- void LoadCategoryScoresFromNode( const XNode* pNode );
- void LoadScreenshotDataFromNode( const XNode* pNode );
- void LoadCalorieDataFromNode( const XNode* pNode );
- void LoadRecentSongScoresFromNode( const XNode* pNode );
- void LoadRecentCourseScoresFromNode( const XNode* pNode );
+ ProfileLoadResult LoadStatsJson( const Json::Value &root, bool bIgnoreEditable = true );
+ void LoadGeneral( const Json::Value &root );
void SaveEditableDataToDir( RString sDir ) const;
bool SaveStatsJsonToDir( RString sDir, bool bSignData ) const;
void SaveGeneral( Json::Value &root ) const;
- void SaveSongScores( Json::Value &root ) const;
- void SaveCourseScores( Json::Value &root ) const;
- void SaveCategoryScores( Json::Value &root ) const;
- void SaveScreenshotData( Json::Value &root ) const;
- void SaveCalorieData( Json::Value &root ) const;
- void SaveRecentSongScores( Json::Value &root ) const;
- void SaveRecentCourseScores( Json::Value &root ) const;
void SaveStatsWebPageToDir( RString sDir ) const;
void SaveMachinePublicKeyToDir( RString sDir ) const;
Modified: branches/4.0/stepmania/src/SongUtil.cpp
==============================================================================
--- branches/4.0/stepmania/src/SongUtil.cpp (original)
+++ branches/4.0/stepmania/src/SongUtil.cpp Wed Dec 29 14:08:42 2010
@@ -857,9 +857,10 @@ void SongID::Serialize( Json::Value &roo
root = sDir;
}
-void SongID::Deserialize( const Json::Value &root )
+bool SongID::Deserialize( const Json::Value &root )
{
sDir = root.asString();
+ return true;
}
RString SongID::ToString() const
Modified: branches/4.0/stepmania/src/SongUtil.h
==============================================================================
--- branches/4.0/stepmania/src/SongUtil.h (original)
+++ branches/4.0/stepmania/src/SongUtil.h Wed Dec 29 14:08:42 2010
@@ -119,7 +119,7 @@ public:
void LoadFromDir( RString _sDir ) { sDir = _sDir; }
void Serialize( Json::Value &root ) const;
- void Deserialize( const Json::Value &root );
+ bool Deserialize( const Json::Value &root );
RString ToString() const;
bool IsValid() const;
Modified: branches/4.0/stepmania/src/StepsUtil.cpp
==============================================================================
--- branches/4.0/stepmania/src/StepsUtil.cpp (original)
+++ branches/4.0/stepmania/src/StepsUtil.cpp Wed Dec 29 14:08:42 2010
@@ -311,7 +311,7 @@ void StepsID::Serialize( Json::Value &ro
}
}
-void StepsID::Deserialize( const Json::Value &root )
+bool StepsID::Deserialize( const Json::Value &root )
{
st = GameManager::StringToStepsType( root["StepsType"].asString() );
dc = StringToDifficulty( root["Difficulty"].asString() );
@@ -326,6 +326,7 @@ void StepsID::Deserialize( const Json::V
sDescription = "";
uHash = 0;
}
+ return true;
}
RString StepsID::ToString() const
Modified: branches/4.0/stepmania/src/StepsUtil.h
==============================================================================
--- branches/4.0/stepmania/src/StepsUtil.h (original)
+++ branches/4.0/stepmania/src/StepsUtil.h Wed Dec 29 14:08:42 2010
@@ -77,7 +77,7 @@ public:
void LoadFromNode( const XNode* pNode );
void Serialize( Json::Value &root ) const;
- void Deserialize( const Json::Value &root );
+ bool Deserialize( const Json::Value &root );
RString ToString() const;
bool IsValid() const;
Modified: branches/4.0/stepmania/src/StyleUtil.cpp
==============================================================================
--- branches/4.0/stepmania/src/StyleUtil.cpp (original)
+++ branches/4.0/stepmania/src/StyleUtil.cpp Wed Dec 29 14:08:42 2010
@@ -58,10 +58,11 @@ void StyleID::Serialize( Json::Value &ro
root["Style"] = sStyle;
}
-void StyleID::Deserialize( const Json::Value &root )
+bool StyleID::Deserialize( const Json::Value &root )
{
sGame = root["Game"].asString();
sStyle = root["Style"].asString();
+ return true;
}
bool StyleID::IsValid() const
Modified: branches/4.0/stepmania/src/StyleUtil.h
==============================================================================
--- branches/4.0/stepmania/src/StyleUtil.h (original)
+++ branches/4.0/stepmania/src/StyleUtil.h Wed Dec 29 14:08:42 2010
@@ -22,7 +22,7 @@ public:
void LoadFromNode( const XNode* pNode );
void Serialize( Json::Value &root ) const;
- void Deserialize( const Json::Value &root );
+ bool Deserialize( const Json::Value &root );
bool IsValid() const;
static void FlushCache( Song* pStaleSong );
Modified: branches/4.0/stepmania/src/TrailUtil.cpp
==============================================================================
--- branches/4.0/stepmania/src/TrailUtil.cpp (original)
+++ branches/4.0/stepmania/src/TrailUtil.cpp Wed Dec 29 14:08:42 2010
@@ -65,10 +65,11 @@ void TrailID::Serialize( Json::Value &ro
root["CourseDifficulty"] = CourseDifficultyToString(cd);
}
-void TrailID::Deserialize( const Json::Value &root )
+bool TrailID::Deserialize( const Json::Value &root )
{
st = GameManager::StringToStepsType( root["StepsType"].asString() );
cd = StringToCourseDifficulty( root["CourseDifficulty"].asString() );
+ return true;
}
RString TrailID::ToString() const
Modified: branches/4.0/stepmania/src/TrailUtil.h
==============================================================================
--- branches/4.0/stepmania/src/TrailUtil.h (original)
+++ branches/4.0/stepmania/src/TrailUtil.h Wed Dec 29 14:08:42 2010
@@ -27,7 +27,7 @@ public:
void LoadFromNode( const XNode* pNode );
void Serialize( Json::Value &root ) const;
- void Deserialize( const Json::Value &root );
+ bool Deserialize( const Json::Value &root );
RString ToString() const;
bool IsValid() const;
Modified: branches/4.0/stepmania/src/UnlockManager.cpp
==============================================================================
--- branches/4.0/stepmania/src/UnlockManager.cpp (original)
+++ branches/4.0/stepmania/src/UnlockManager.cpp Wed Dec 29 14:08:42 2010
@@ -190,15 +190,15 @@ const UnlockEntry *UnlockManager::FindMo
static float GetArcadePoints( const Profile *pProfile )
{
- float fAP = 0;
+ float fAP = 0;
FOREACH_Grade(g)
{
switch(g)
{
case Grade_Tier01:
- case Grade_Tier02: fAP += 9 * pProfile->m_iNumStagesPassedByGrade[g]; break;
- default: fAP += 1 * pProfile->m_iNumStagesPassedByGrade[g]; break;
+ case Grade_Tier02: fAP += 9 * pProfile->GetNumStagesPassedByGrade(g); break;
+ default: fAP += 1 * pProfile->GetNumStagesPassedByGrade(g); break;
case Grade_Failed:
case Grade_NoData:
@@ -214,7 +214,7 @@ static float GetArcadePoints( const Prof
case PLAY_MODE_NONSTOP:
case PLAY_MODE_ONI:
case PLAY_MODE_ENDLESS:
- fAP += pProfile->m_iNumSongsPlayedByPlayMode[pm];
+ fAP += pProfile->GetNumSongsPlayedByPlayMode(pm);
break;
}
@@ -231,13 +231,13 @@ static float GetSongPoints( const Profil
{
switch( g )
{
- case Grade_Tier01:/*AAAA*/ fSP += 20 * pProfile->m_iNumStagesPassedByGrade[g]; break;
- case Grade_Tier02:/*AAA*/ fSP += 10* pProfile->m_iNumStagesPassedByGrade[g]; break;
- case Grade_Tier03:/*AA*/ fSP += 5* pProfile->m_iNumStagesPassedByGrade[g]; break;
- case Grade_Tier04:/*A*/ fSP += 4* pProfile->m_iNumStagesPassedByGrade[g]; break;
- case Grade_Tier05:/*B*/ fSP += 3* pProfile->m_iNumStagesPassedByGrade[g]; break;
- case Grade_Tier06:/*C*/ fSP += 2* pProfile->m_iNumStagesPassedByGrade[g]; break;
- case Grade_Tier07:/*D*/ fSP += 1* pProfile->m_iNumStagesPassedByGrade[g]; break;
+ case Grade_Tier01:/*AAAA*/ fSP += 20 * pProfile->GetNumStagesPassedByGrade(g); break;
+ case Grade_Tier02:/*AAA*/ fSP += 10* pProfile->GetNumStagesPassedByGrade(g); break;
+ case Grade_Tier03:/*AA*/ fSP += 5* pProfile->GetNumStagesPassedByGrade(g); break;
+ case Grade_Tier04:/*A*/ fSP += 4* pProfile->GetNumStagesPassedByGrade(g); break;
+ case Grade_Tier05:/*B*/ fSP += 3* pProfile->GetNumStagesPassedByGrade(g); break;
+ case Grade_Tier06:/*C*/ fSP += 2* pProfile->GetNumStagesPassedByGrade(g); break;
+ case Grade_Tier07:/*D*/ fSP += 1* pProfile->GetNumStagesPassedByGrade(g); break;
case Grade_Failed:
case Grade_NoData:
; // no points
@@ -252,7 +252,7 @@ static float GetSongPoints( const Profil
case PLAY_MODE_NONSTOP:
case PLAY_MODE_ONI:
case PLAY_MODE_ENDLESS:
- fSP += pProfile->m_iNumSongsPlayedByPlayMode[pm];
+ fSP += pProfile->GetNumSongsPlayedByPlayMode(pm);
break;
}
|
|
From: Chris D. <de...@st...> - 2010-12-29 02:40:50
|
Modified:
branches/4.0/stepmania/src/JsonUtil.h
branches/4.0/stepmania/src/Profile.cpp
branches/4.0/stepmania/src/Profile.h
Log:
finish JSON serialization of Profile
Modified: branches/4.0/stepmania/src/JsonUtil.h
==============================================================================
--- branches/4.0/stepmania/src/JsonUtil.h (original)
+++ branches/4.0/stepmania/src/JsonUtil.h Tue Dec 28 18:40:43 2010
@@ -64,6 +64,20 @@ namespace JsonUtil
iter->Serialize( root[i++] );
}
+ template <typename M, typename E>
+ static void SerializeEnumToObjectMap(const M &m, const RString &fnEnumToString(E e), Json::Value &root)
+ {
+ for( M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
+ iter->second.Serialize( root[ fnEnumToString(iter->first) ] );
+ }
+
+ template <typename M>
+ static void SerializeValueToValueMap(const M &m, Json::Value &root)
+ {
+ for( M::const_iterator iter=m.begin(); iter!=m.end(); iter++ )
+ root[ (iter->first).GetString() ] = iter->second;
+ }
+
// Serialize a map that has a non-string key type
template <typename V>
static void SerializeMapAsArray(const V &v, const RString &sKeyName, const RString &sValueName, Json::Value &root)
Modified: branches/4.0/stepmania/src/Profile.cpp
==============================================================================
--- branches/4.0/stepmania/src/Profile.cpp (original)
+++ branches/4.0/stepmania/src/Profile.cpp Tue Dec 28 18:40:43 2010
@@ -156,9 +156,7 @@ void Profile::InitCourseScores()
void Profile::InitCategoryScores()
{
- for( int st=0; st<NUM_STEPS_TYPES; st++ )
- for( int rc=0; rc<NUM_RANKING_CATEGORIES; rc++ )
- m_CategoryHighScores[st][rc].Init();
+ m_CategoryHighScores.clear();
}
void Profile::InitScreenshotData()
@@ -745,31 +743,34 @@ void Profile::IncrementCoursePlayCount(
//
void Profile::AddCategoryHighScore( StepsType st, RankingCategory rc, HighScore hs, int &iIndexOut )
{
- m_CategoryHighScores[st][rc].AddHighScore( hs, iIndexOut, IsMachine() );
+ m_CategoryHighScores[st].m_v[rc].AddHighScore( hs, iIndexOut, IsMachine() );
}
const HighScoreList& Profile::GetCategoryHighScoreList( StepsType st, RankingCategory rc ) const
{
- return ((Profile *)this)->m_CategoryHighScores[st][rc];
+ return ((Profile *)this)->m_CategoryHighScores[st].m_v[rc];
}
HighScoreList& Profile::GetCategoryHighScoreList( StepsType st, RankingCategory rc )
{
- return m_CategoryHighScores[st][rc];
+ return m_CategoryHighScores[st].m_v[rc];
}
int Profile::GetCategoryNumTimesPlayed( StepsType st ) const
{
int iNumTimesPlayed = 0;
- FOREACH_RankingCategory( rc )
- iNumTimesPlayed += m_CategoryHighScores[st][rc].GetNumTimesPlayed();
+ map<StepsType,RankingCategoryToHighScoreList>::const_iterator iter1 = m_CategoryHighScores.find(st);
+ if( iter1 == m_CategoryHighScores.end() )
+ return 0;
+ FOREACHM_CONST( RankingCategory, HighScoreList, iter1->second.m_v, iter2 )
+ iNumTimesPlayed += iter2->second.GetNumTimesPlayed();
return iNumTimesPlayed;
}
void Profile::IncrementCategoryPlayCount( StepsType st, RankingCategory rc )
{
DateTime now = DateTime::GetNowDate();
- m_CategoryHighScores[st][rc].IncrementPlayCount( now );
+ m_CategoryHighScores[st].m_v[rc].IncrementPlayCount( now );
}
@@ -916,17 +917,35 @@ bool Profile::SaveAllToDir( RString sDir
return bSaved;
}
+
+void Profile::RankingCategoryToHighScoreList::Serialize( Json::Value &root ) const
+{
+ JsonUtil::SerializeEnumToObjectMap( m_v, RankingCategoryToString, root );
+}
+
+void Profile::RankingCategoryToHighScoreList::Deserialize( const Json::Value &root )
+{
+ FAIL_M("unfinished");
+}
+
bool Profile::SaveStatsJsonToDir( RString sDir, bool bSignData ) const
{
Json::Value root;
SaveGeneral( root["General"] );
- SaveSongScores( root["SongScores"] );
- SaveCourseScores( root["CourseScores"] );
- SaveCategoryScores( root["CategoryScores"] );
- SaveScreenshotData( root["ScreenshotData"] );
- SaveCalorieData( root["CalorieData"] );
- SaveRecentSongScores( root["RecentSongScores"] );
- SaveRecentCourseScores( root["RecentCourseScores"] );
+
+ JsonUtil::SerializeMapAsArray( m_SongHighScores, "Song", "HighScoresForASong", root["SongScores"] );
+
+ JsonUtil::SerializeMapAsArray( m_CourseHighScores, "Course", "HighScoresForACourse", root["CourseScores"] );
+
+ JsonUtil::SerializeEnumToObjectMap( m_CategoryHighScores, StepsTypeToString, root["CategoryScores"] );
+
+ JsonUtil::SerializeArrayObjects( m_vScreenshots, root["ScreenshotData"] );
+
+ JsonUtil::SerializeValueToValueMap( m_mapDayToCaloriesBurned, root["CalorieData"] );
+
+ JsonUtil::SerializeArrayObjects( m_vRecentStepsScores, root["RecentSongScores"] );
+
+ JsonUtil::SerializeArrayObjects( m_vRecentCourseScores, root["RecentCourseScores"] );
RString fn = sDir + STATS_JSON;
bool bSaved = JsonUtil::WriteFile( root, fn, false );
@@ -1289,7 +1308,6 @@ void Profile::SaveSongScores( Json::Valu
{
CHECKPOINT;
ASSERT( this );
- JsonUtil::SerializeMapAsArray( m_SongHighScores, "Song", "HighScoresForASong", root );
}
void Profile::LoadSongScoresFromNode( const XNode* pSongScores )
@@ -1337,7 +1355,6 @@ void Profile::SaveCourseScores( Json::Va
{
CHECKPOINT;
ASSERT( this );
- JsonUtil::SerializeMapAsArray( m_CourseHighScores, "Course", "HighScoresForACourse", root );
}
void Profile::LoadCourseScoresFromNode( const XNode* pCourseScores )
@@ -1413,24 +1430,6 @@ void Profile::SaveCategoryScores( Json::
CHECKPOINT;
ASSERT( this );
- FOREACH_StepsType( st )
- {
- // skip steps types that have never been played
- if( GetCategoryNumTimesPlayed( st ) == 0 )
- continue;
-
- Json::Value &v = root[ GameManager::StepsTypeToString(st) ];
-
- FOREACH_RankingCategory( rc )
- {
- // skip steps types/categories that have never been played
- if( GetCategoryHighScoreList(st,rc).GetNumTimesPlayed() == 0 )
- continue;
-
- const HighScoreList &hsl = GetCategoryHighScoreList( (StepsType)st, (RankingCategory)rc );
- hsl.Serialize( v[ RankingCategoryToString(rc) ] );
- }
- }
}
void Profile::LoadCategoryScoresFromNode( const XNode* pCategoryScores )
@@ -1514,7 +1513,6 @@ void Profile::LoadScreenshotDataFromNode
void Profile::SaveScreenshotData( Json::Value &root ) const
{
CHECKPOINT;
- JsonUtil::SerializeArrayObjects( m_vScreenshots, root );
}
void Profile::LoadCalorieDataFromNode( const XNode* pCalorieData )
@@ -1547,8 +1545,6 @@ void Profile::SaveCalorieData( Json::Val
CHECKPOINT;
ASSERT( this );
- FOREACHM_CONST( DateTime, float, m_mapDayToCaloriesBurned, iter )
- root[ iter->first.GetString() ] = iter->second;
}
float Profile::GetCaloriesBurnedForDay( DateTime day ) const
@@ -1626,7 +1622,6 @@ void Profile::SaveRecentSongScores( Json
{
CHECKPOINT;
ASSERT( this );
- JsonUtil::SerializeArrayObjects( m_vRecentStepsScores, root );
}
void Profile::AddStepsRecentScore( const Song* pSong, const Steps* pSteps, HighScore hs )
@@ -1709,7 +1704,6 @@ void Profile::SaveRecentCourseScores( Js
{
CHECKPOINT;
ASSERT( this );
- JsonUtil::SerializeArrayObjects( m_vRecentCourseScores, root );
}
void Profile::AddCourseRecentScore( const Course* pCourse, const Trail* pTrail, HighScore hs )
Modified: branches/4.0/stepmania/src/Profile.h
==============================================================================
--- branches/4.0/stepmania/src/Profile.h (original)
+++ branches/4.0/stepmania/src/Profile.h Tue Dec 28 18:40:43 2010
@@ -183,7 +183,7 @@ public:
void Serialize( Json::Value &root ) const;
void Deserialize( const Json::Value &root );
};
- std::map<CourseID,HighScoresForACourse> m_CourseHighScores;
+ map<CourseID,HighScoresForACourse> m_CourseHighScores;
void AddCourseHighScore( const Course* pCourse, const Trail* pTrail, HighScore hs, int &iIndexOut );
HighScoreList& GetCourseHighScoreList( const Course* pCourse, const Trail* pTrail );
@@ -197,7 +197,14 @@ public:
//
// Category high scores
//
- HighScoreList m_CategoryHighScores[NUM_STEPS_TYPES][NUM_RANKING_CATEGORIES];
+ struct RankingCategoryToHighScoreList
+ {
+ map<RankingCategory,HighScoreList> m_v;
+
+ void Serialize( Json::Value &root ) const;
+ void Deserialize( const Json::Value &root );
+ };
+ map<StepsType,RankingCategoryToHighScoreList> m_CategoryHighScores;
void AddCategoryHighScore( StepsType st, RankingCategory rc, HighScore hs, int &iIndexOut );
HighScoreList& GetCategoryHighScoreList( StepsType st, RankingCategory rc );
|
|
From: Chris D. <de...@st...> - 2010-12-29 02:40:22
|
Modified:
branches/4.0/stepmania/src/GameConstantsAndTypes.cpp
branches/4.0/stepmania/src/GameConstantsAndTypes.h
branches/4.0/stepmania/src/GameManager.cpp
branches/4.0/stepmania/src/Song.cpp
branches/4.0/stepmania/src/song.h
Log:
clean up StepsType enum for easier serializing
Modified: branches/4.0/stepmania/src/GameConstantsAndTypes.cpp
==============================================================================
--- branches/4.0/stepmania/src/GameConstantsAndTypes.cpp (original)
+++ branches/4.0/stepmania/src/GameConstantsAndTypes.cpp Tue Dec 28 18:40:15 2010
@@ -43,6 +43,40 @@ static void LuaRadarCategory(lua_State*
}
REGISTER_WITH_LUA_FUNCTION( LuaRadarCategory );
+static const char *StepsTypeNames[] = {
+ "dance-single",
+ "dance-double",
+ "dance-couple",
+ "dance-solo",
+ "dance-routine",
+ "pump-single",
+ "pump-halfdouble",
+ "pump-double",
+ "pump-couple",
+ "ez2-single", // Single: TL,LHH,D,RHH,TR
+ "ez2-double", // Double: Single x2
+ "ez2-real", // Real: TL,LHH,LHL,D,RHL,RHH,TR
+ "para-single",
+ "para-versus",
+ "ds3ddx-single",
+ "bm-single5", // called "bm" for backward compat
+ "bm-double5", // called "bm" for backward compat
+ "bm-single7", // called "bm" for backward compat
+ "bm-double7", // called "bm" for backward compat
+ "maniax-single",
+ "maniax-double",
+ "techno-single4",
+ "techno-single5",
+ "techno-single8",
+ "techno-double4",
+ "techno-double5",
+ "pnm-five",
+ "pnm-nine",
+ "lights-cabinet",
+};
+XToString( StepsType, NUM_StepsType );
+StringToX( StepsType );
+
static void LuaStepsType(lua_State* L)
{
FOREACH_StepsType( st )
Modified: branches/4.0/stepmania/src/GameConstantsAndTypes.h
==============================================================================
--- branches/4.0/stepmania/src/GameConstantsAndTypes.h (original)
+++ branches/4.0/stepmania/src/GameConstantsAndTypes.h Tue Dec 28 18:40:15 2010
@@ -67,10 +67,12 @@ enum StepsType
STEPS_TYPE_POPN_FIVE,
STEPS_TYPE_POPN_NINE,
STEPS_TYPE_LIGHTS_CABINET,
- NUM_STEPS_TYPES, // leave this at the end
+ NUM_StepsType, // leave this at the end
STEPS_TYPE_INVALID,
};
-#define FOREACH_StepsType( st ) FOREACH_ENUM( StepsType, NUM_STEPS_TYPES, st )
+#define FOREACH_StepsType( st ) FOREACH_ENUM( StepsType, NUM_StepsType, st )
+const RString& StepsTypeToString( StepsType v );
+StepsType StringToStepsType( const RString& s );
//
// Play mode stuff
Modified: branches/4.0/stepmania/src/GameManager.cpp
==============================================================================
--- branches/4.0/stepmania/src/GameManager.cpp (original)
+++ branches/4.0/stepmania/src/GameManager.cpp Tue Dec 28 18:40:15 2010
@@ -65,39 +65,37 @@ const int TECHNO_VERSUS_COL_SPACING = 33
const int POPN5_COL_SPACING = 32;
const int POPN9_COL_SPACING = 32;
-static struct {
- char *name;
- int NumTracks;
-} const StepsTypes[NUM_STEPS_TYPES] = {
- { "dance-single", 4 },
- { "dance-double", 8 },
- { "dance-couple", 8 },
- { "dance-solo", 6 },
- { "dance-routine", 8 },
- { "pump-single", 5 },
- { "pump-halfdouble",6 },
- { "pump-double", 10 },
- { "pump-couple", 10 },
- { "ez2-single", 5 }, // Single: TL,LHH,D,RHH,TR
- { "ez2-double", 10 }, // Double: Single x2
- { "ez2-real", 7 }, // Real: TL,LHH,LHL,D,RHL,RHH,TR
- { "para-single", 5 },
- { "para-versus", 10 },
- { "ds3ddx-single", 8 },
- { "bm-single5", 6 }, // called "bm" for backward compat
- { "bm-double5", 12 }, // called "bm" for backward compat
- { "bm-single7", 8 }, // called "bm" for backward compat
- { "bm-double7", 16 }, // called "bm" for backward compat
- { "maniax-single", 4 },
- { "maniax-double", 8 },
- { "techno-single4", 4 },
- { "techno-single5", 5 },
- { "techno-single8", 8 },
- { "techno-double4", 8 },
- { "techno-double5", 10 },
- { "pnm-five", 5 }, // called "pnm" for backward compat
- { "pnm-nine", 9 }, // called "pnm" for backward compat
- { "lights-cabinet", NUM_CABINET_LIGHTS },
+static const int g_iNumTracks[NUM_StepsType] =
+{
+ 4, // dance-single
+ 8, // dance-double
+ 8, // dance-couple
+ 6, // dance-solo",
+ 8, // dance-routine",
+ 5, // pump-single",
+ 6, // pump-halfdouble
+ 10, // pump-double",,
+ 10, // pump-couple",,
+ 5, // ez2-single", // Single: TL,LHH,D,RHH,TR
+ 10, // ez2-double", , // Double: Single x2
+ 7, // ez2-real", // Real: TL,LHH,LHL,D,RHL,RHH,TR
+ 5, // para-single",
+ 10, // para-versus",,
+ 8, // ds3ddx-single",
+ 6, // bm-single5", // called "bm" for backward compat
+ 12, // bm-double5", // called "bm" for backward compat
+ 8, // bm-single7", // called "bm" for backward compat
+ 16, // bm-double7", // called "bm" for backward compat
+ 4, // maniax-single",
+ 8, // maniax-double",
+ 4, // techno-single4"
+ 5, // techno-single5"
+ 8, // techno-single8"
+ 8, // techno-double4"
+ 10, // techno-double5"
+ 5, // pnm-five", // called "pnm" for backward compat
+ 9, // pnm-nine", // called "pnm" for backward compat
+ NUM_CABINET_LIGHTS, // lights-cabinet
};
//
@@ -2762,12 +2760,13 @@ bool GameManager::IsGameEnabled( const G
int GameManager::StepsTypeToNumTracks( StepsType st )
{
- ASSERT_M( st < NUM_STEPS_TYPES, ssprintf("%i", st) );
- return StepsTypes[st].NumTracks;
+ ASSERT_M( st < NUM_StepsType, ssprintf("%i", st) );
+ return g_iNumTracks[st];
}
StepsType GameManager::StringToStepsType( RString sStepsType )
{
+ // HACK
sStepsType.MakeLower();
// HACK! We elminitated "ez2-single-hard", but we should still handle it.
@@ -2778,19 +2777,12 @@ StepsType GameManager::StringToStepsType
if( sStepsType == "para" )
sStepsType = "para-single";
- for( int i=0; i<NUM_STEPS_TYPES; i++ )
- if( StepsTypes[i].name == sStepsType )
- return StepsType(i);
-
- // invalid StepsType
- LOG->Warn( "Invalid StepsType string '%s' encountered. Assuming this is 'dance-single'.", sStepsType.c_str() );
- return STEPS_TYPE_DANCE_SINGLE;
+ return ::StringToStepsType( sStepsType );
}
RString GameManager::StepsTypeToString( StepsType st )
{
- ASSERT_M( st < NUM_STEPS_TYPES, ssprintf("%i", st) );
- return StepsTypes[st].name;
+ return ::StepsTypeToString(st);
}
RString GameManager::StepsTypeToLocalizedString( StepsType st )
Modified: branches/4.0/stepmania/src/Song.cpp
==============================================================================
--- branches/4.0/stepmania/src/Song.cpp (original)
+++ branches/4.0/stepmania/src/Song.cpp Tue Dec 28 18:40:15 2010
@@ -811,7 +811,7 @@ void Song::SaveToDWIFile()
void Song::AddAutoGenNotes()
{
- bool HasNotes[NUM_STEPS_TYPES];
+ bool HasNotes[NUM_StepsType];
memset( HasNotes, 0, sizeof(HasNotes) );
for( unsigned i=0; i < m_vpSteps.size(); i++ ) // foreach Steps
{
@@ -1102,7 +1102,7 @@ RString Song::GetTranslitFullTitle() con
void Song::AddSteps( Steps* pSteps )
{
m_vpSteps.push_back( pSteps );
- ASSERT_M( pSteps->m_StepsType < NUM_STEPS_TYPES, ssprintf("%i", pSteps->m_StepsType) );
+ ASSERT_M( pSteps->m_StepsType < NUM_StepsType, ssprintf("%i", pSteps->m_StepsType) );
m_vpStepsByType[pSteps->m_StepsType].push_back( pSteps );
}
Modified: branches/4.0/stepmania/src/song.h
==============================================================================
--- branches/4.0/stepmania/src/song.h (original)
+++ branches/4.0/stepmania/src/song.h Tue Dec 28 18:40:15 2010
@@ -234,7 +234,7 @@ public:
private:
vector<Steps*> m_vpSteps;
- vector<Steps*> m_vpStepsByType[NUM_STEPS_TYPES];
+ vector<Steps*> m_vpStepsByType[NUM_StepsType];
};
#endif
|