Skip to content

Commit

Permalink
Merge pull request #360 from ayuer/force_republish
Browse files Browse the repository at this point in the history
Fix issue #329, Force republish
  • Loading branch information
Viktor Lidholt committed May 13, 2013
2 parents e46061b + 05c0368 commit 26b1136
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CocosBuilder/ccBuilder/CCBPublisher.m
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,13 @@ - (BOOL) publishAllToDirectory:(NSString*)dir
publishedResources = [NSMutableSet set];
renamedFiles = [NSMutableDictionary dictionary];

//Remove old dir if we need to re-publish due to version mismatch
if (projectSettings.needRepublish)
{
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:dir error:NULL];
}

// Setup paths for automatically generated sprite sheets
generatedSpriteSheetDirs = [NSMutableArray array];
for (NSString* dir in projectSettings.generatedSpriteSheets)
Expand Down Expand Up @@ -1088,6 +1095,12 @@ - (BOOL) publish_
}
}

// Once published, set needRepublish back to NO
if (projectSettings.needRepublish)
{
projectSettings.needRepublish = NO;
[projectSettings store];
}
return YES;
}

Expand Down
4 changes: 3 additions & 1 deletion CocosBuilder/ccBuilder/CocosBuilderAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ - (BOOL) openProject:(NSString*) fileName
return NO;
}
project.projectPath = fileName;

[project store];
self.projectSettings = project;

[self updateResourcePathsFromProjectSettings];
Expand Down Expand Up @@ -2281,6 +2281,8 @@ - (IBAction)menuPublishProjectAndRunInBrowser:(id)sender

- (IBAction) menuCleanCacheDirectories:(id)sender
{
projectSettings.needRepublish = YES;
[projectSettings store];
[CCBPublisher cleanAllCacheDirectories];
}

Expand Down
5 changes: 5 additions & 0 deletions CocosBuilder/ccBuilder/ProjectSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
BOOL deviceOrientationLandscapeLeft;
BOOL deviceOrientationLandscapeRight;
int resourceAutoScaleFactor;

NSString* versionStr;
BOOL needRepublish;
}

@property (nonatomic, copy) NSString* projectPath;
Expand Down Expand Up @@ -150,6 +153,8 @@
@property (nonatomic, readonly) NSDictionary* generatedSpriteSheets;

@property (nonatomic,readonly) NSDictionary* breakpoints;
@property (nonatomic, copy) NSString* versionStr;
@property (nonatomic, assign) BOOL needRepublish;

- (id) initWithSerialization:(id)dict;
- (BOOL) store;
Expand Down
23 changes: 23 additions & 0 deletions CocosBuilder/ccBuilder/ProjectSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ @implementation ProjectSettings
@synthesize resourceAutoScaleFactor;
@synthesize generatedSpriteSheets;
@synthesize breakpoints;
@synthesize versionStr;
@synthesize needRepublish;

- (id) init
{
Expand Down Expand Up @@ -196,6 +198,8 @@ - (id) init
}

[self detectBrowserPresence];
self.versionStr = [self getVersion];
self.needRepublish = NO;
return self;
}

Expand Down Expand Up @@ -273,6 +277,15 @@ - (id) initWithSerialization:(id)dict
self.javascriptMainCCB = mainCCB;

[self detectBrowserPresence];
NSString* old = [dict objectForKey:@"versionStr"];
NSString* new = [self getVersion];
if(![new isEqual:old])
{
self.versionStr = [self getVersion];
self.needRepublish = YES;
}else{
self.needRepublish = NO;
}
return self;
}

Expand Down Expand Up @@ -350,6 +363,8 @@ - (id) serialize
}
[dict setObject:generatedSpriteSheetsDict forKey:@"generatedSpriteSheets"];

[dict setObject:versionStr forKey:@"versionStr"];
[dict setObject:[NSNumber numberWithBool:needRepublish] forKey:@"needRepublish"];
return dict;
}

Expand Down Expand Up @@ -507,4 +522,12 @@ - (void) detectBrowserPresence
isFirefoxExist = TRUE;
}
}

- (NSString* ) getVersion
{
NSString* versionPath = [[NSBundle mainBundle] pathForResource:@"Version" ofType:@"txt" inDirectory:@"version"];

NSString* version = [NSString stringWithContentsOfFile:versionPath encoding:NSUTF8StringEncoding error:NULL];
return version;
}
@end

0 comments on commit 26b1136

Please sign in to comment.