More cool stuff...

- The holy grail! I took Klaas' great autonib2cib and rolled it into nib2cib.
- Removed check for stream in CPLogColorize, it isn't necessary and reduces its general-purpose usage.
This commit is contained in:
Aparajita Fishman
2011-03-29 16:06:19 -04:00
parent d00a8b9d18
commit 16bacae7e3
3 changed files with 159 additions and 61 deletions
+27 -34
View File
@@ -71,46 +71,39 @@ ConverterConversionException = @"ConverterConversionException";
- (void)convert
{
try
if ([resourcesPath length] && !FILE.isReadable(resourcesPath))
[CPException raise:ConverterConversionException reason:@"Could not read Resources at path \"" + resourcesPath + "\""];
var inferredFormat = format;
if (inferredFormat === NibFormatUndetermined)
{
if ([resourcesPath length] && !FILE.isReadable(resourcesPath))
[CPException raise:ConverterConversionException reason:@"Could not read Resources at path \"" + resourcesPath + "\""];
// Assume its a Mac file.
inferredFormat = NibFormatMac;
var inferredFormat = format;
if (inferredFormat === NibFormatUndetermined)
{
// Assume its a Mac file.
inferredFormat = NibFormatMac;
// Some .xibs are iPhone nibs, check the actual contents in this case.
if (FILE.extension(inputPath) !== ".nib" && FILE.isFile(inputPath) &&
FILE.read(inputPath, { charset:"UTF-8" }).indexOf("<archive type=\"com.apple.InterfaceBuilder3.CocoaTouch.XIB\"") !== -1)
inferredFormat = NibFormatIPhone;
if (inferredFormat === NibFormatMac)
CPLog.info("Auto-detected Cocoa Nib or Xib File");
else
CPLog.info("Auto-detected CocoaTouch Xib File");
}
var nibData = [self CPCompliantNibDataAtFilePath:inputPath];
// Some .xibs are iPhone nibs, check the actual contents in this case.
if (FILE.extension(inputPath) !== ".nib" && FILE.isFile(inputPath) &&
FILE.read(inputPath, { charset:"UTF-8" }).indexOf("<archive type=\"com.apple.InterfaceBuilder3.CocoaTouch.XIB\"") !== -1)
inferredFormat = NibFormatIPhone;
if (inferredFormat === NibFormatMac)
var convertedData = [self convertedDataFromMacData:nibData resourcesPath:resourcesPath];
CPLog.info("Auto-detected Cocoa Nib or Xib File");
else
[CPException raise:ConverterConversionException reason:@"nib2cib does not understand this nib format."];
if (![outputPath length])
outputPath = inputPath.substr(0, inputPath.length - FILE.extension(inputPath).length) + ".cib";
FILE.write(outputPath, [convertedData rawString], { charset:"UTF-8" });
CPLog.info("Conversion successful");
}
catch (anException)
{
CPLog.fatal(anException);
CPLog.info("Auto-detected CocoaTouch Xib File");
}
var nibData = [self CPCompliantNibDataAtFilePath:inputPath];
if (inferredFormat === NibFormatMac)
var convertedData = [self convertedDataFromMacData:nibData resourcesPath:resourcesPath];
else
[CPException raise:ConverterConversionException reason:@"nib2cib does not understand this nib format."];
if (![outputPath length])
outputPath = inputPath.substr(0, inputPath.length - FILE.extension(inputPath).length) + ".cib";
FILE.write(outputPath, [convertedData rawString], { charset:"UTF-8" });
CPLog.info(CPLogColorize("Conversion successful", "warn"));
}
- (CPData)CPCompliantNibDataAtFilePath:(CPString)aFilePath