| 1 | 
           cycrow | 
           1 | 
           #include "spk.h"
  | 
        
        
            | 
            | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           namespace SPK {
  | 
        
        
           | 18 | 
           cycrow | 
           4 | 
           	s_int GetAutomaticFiletype(CyString file, CyString *extradir, bool bUseSpecial)
  | 
        
        
           | 1 | 
           cycrow | 
           5 | 
           	{
  | 
        
        
            | 
            | 
           6 | 
           		CFileIO File(file);
  | 
        
        
           | 121 | 
           cycrow | 
           7 | 
           		Utils::String dir = File.GetDirIO().topDir();
  | 
        
        
           | 1 | 
           cycrow | 
           8 | 
              | 
        
        
           | 57 | 
           cycrow | 
           9 | 
           		CyString basename = File.baseName();
  | 
        
        
           | 1 | 
           cycrow | 
           10 | 
           		// could be a script, text file or map
  | 
        
        
            | 
            | 
           11 | 
           		s_int type = -1;
  | 
        
        
            | 
            | 
           12 | 
           		if ( dir.Compare("types") || dir.Compare("mov") || dir.Compare("s") )
  | 
        
        
            | 
            | 
           13 | 
           		{
  | 
        
        
            | 
            | 
           14 | 
           			type = FILETYPE_EXTRA;
  | 
        
        
            | 
            | 
           15 | 
           			if ( extradir )
  | 
        
        
            | 
            | 
           16 | 
           				*extradir = dir;
  | 
        
        
            | 
            | 
           17 | 
           		}
  | 
        
        
            | 
            | 
           18 | 
           		else if ( File.CheckFileExtension("xml") || File.CheckFileExtension("pck") )
  | 
        
        
            | 
            | 
           19 | 
           		{
  | 
        
        
            | 
            | 
           20 | 
           			// TC text file
  | 
        
        
            | 
            | 
           21 | 
           			type = FILETYPE_SCRIPT;
  | 
        
        
           | 57 | 
           cycrow | 
           22 | 
           			if ( File.filename().isin("-L") && ((int)File.filename().left(4)) )
  | 
        
        
           | 1 | 
           cycrow | 
           23 | 
           				type = FILETYPE_TEXT;
  | 
        
        
           | 57 | 
           cycrow | 
           24 | 
           			if ( File.baseName().Compare("conversations") )
  | 
        
        
           | 43 | 
           cycrow | 
           25 | 
           				type = FILETYPE_TEXT;
  | 
        
        
           | 1 | 
           cycrow | 
           26 | 
           			// X2/X3 text file
  | 
        
        
           | 57 | 
           cycrow | 
           27 | 
           			else if ( basename.Length() >= 5 && basename.Length() <= 8 && ((int)File.baseName()) )
  | 
        
        
           | 1 | 
           cycrow | 
           28 | 
           				type = FILETYPE_TEXT;
  | 
        
        
            | 
            | 
           29 | 
           			else if ( dir.Compare("maps") )
  | 
        
        
            | 
            | 
           30 | 
           				type = FILETYPE_MAP;
  | 
        
        
            | 
            | 
           31 | 
           			else if ( dir.Compare("t") )
  | 
        
        
            | 
            | 
           32 | 
           				type = FILETYPE_TEXT;
  | 
        
        
           | 18 | 
           cycrow | 
           33 | 
           			else if ( (bUseSpecial) && (dir.Compare("scripts") && basename.IsIn("uninstall")) )
  | 
        
        
            | 
            | 
           34 | 
           				type = FILETYPE_SCRIPT_UNINSTALL;
  | 
        
        
           | 1 | 
           cycrow | 
           35 | 
           			else if ( dir.Compare("uninstall") || basename.IsIn("uninstall") )
  | 
        
        
            | 
            | 
           36 | 
           				type = FILETYPE_UNINSTALL;
  | 
        
        
           | 121 | 
           cycrow | 
           37 | 
           			else if ( dir.isin("uninstall") )
  | 
        
        
           | 18 | 
           cycrow | 
           38 | 
           				type = FILETYPE_UNINSTALL;
  | 
        
        
           | 1 | 
           cycrow | 
           39 | 
           			else if ( dir.Compare("director") )
  | 
        
        
            | 
            | 
           40 | 
           				type = FILETYPE_MISSION;
  | 
        
        
            | 
            | 
           41 | 
           		}
  | 
        
        
            | 
            | 
           42 | 
           		// could be a model file or scene file
  | 
        
        
            | 
            | 
           43 | 
           		else if ( File.CheckFileExtension("pbd") || File.CheckFileExtension("bod") )
  | 
        
        
            | 
            | 
           44 | 
           		{
  | 
        
        
           | 121 | 
           cycrow | 
           45 | 
           			if ( dir.isin("cockpit") || basename.IsIn("cockpit") )
  | 
        
        
           | 1 | 
           cycrow | 
           46 | 
           				type = FILETYPE_COCKPITSCENE;
  | 
        
        
            | 
            | 
           47 | 
           			else
  | 
        
        
            | 
            | 
           48 | 
           				type = FILETYPE_SHIPSCENE;
  | 
        
        
            | 
            | 
           49 | 
           		}
  | 
        
        
            | 
            | 
           50 | 
           		// can only be a model
  | 
        
        
            | 
            | 
           51 | 
           		else if ( File.CheckFileExtension("pbb") || File.CheckFileExtension("bob") )
  | 
        
        
            | 
            | 
           52 | 
           			type = FILETYPE_SHIPMODEL;
  | 
        
        
            | 
            | 
           53 | 
           		// texture file
  | 
        
        
            | 
            | 
           54 | 
           		else if ( File.CheckFileExtension("dds") )
  | 
        
        
            | 
            | 
           55 | 
           			type = FILETYPE_SHIPOTHER;
  | 
        
        
            | 
            | 
           56 | 
           		else if ( File.CheckFileExtension("txt") || dir.Compare("readme") )
  | 
        
        
            | 
            | 
           57 | 
           			type = FILETYPE_README;
  | 
        
        
            | 
            | 
           58 | 
           		else if ( File.CheckFileExtension("cat") || File.CheckFileExtension("dat") )
  | 
        
        
            | 
            | 
           59 | 
           			type = FILETYPE_MOD;
  | 
        
        
            | 
            | 
           60 | 
           		else if ( File.CheckFileExtension("mp3") )
  | 
        
        
            | 
            | 
           61 | 
           			type = FILETYPE_SOUND;
  | 
        
        
            | 
            | 
           62 | 
           		else if ( dir.Compare("loadscr") )
  | 
        
        
            | 
            | 
           63 | 
           			type = FILETYPE_SCREEN;
  | 
        
        
            | 
            | 
           64 | 
           		else if ( dir.Compare("graphics") )
  | 
        
        
            | 
            | 
           65 | 
           			type = FILETYPE_ADVERT;
  | 
        
        
            | 
            | 
           66 | 
           		else if ( File.CheckFileExtension("jpg") || File.CheckFileExtension("bmp") )
  | 
        
        
            | 
            | 
           67 | 
           			type = FILETYPE_SCREEN;
  | 
        
        
            | 
            | 
           68 | 
           		else if ( File.CheckFileExtension("gif") )
  | 
        
        
            | 
            | 
           69 | 
           			type = FILETYPE_ADVERT;
  | 
        
        
            | 
            | 
           70 | 
              | 
        
        
            | 
            | 
           71 | 
           		return type;
  | 
        
        
            | 
            | 
           72 | 
           	}
  | 
        
        
            | 
            | 
           73 | 
              | 
        
        
           | 18 | 
           cycrow | 
           74 | 
           	//TODO: check for special types
  | 
        
        
           | 1 | 
           cycrow | 
           75 | 
           	void AssignAutomaticFiletypes(CyStringList *list)
  | 
        
        
            | 
            | 
           76 | 
           	{
  | 
        
        
            | 
            | 
           77 | 
           		for ( SStringList *str = list->Head(); str; str = str->next )
  | 
        
        
            | 
            | 
           78 | 
           		{
  | 
        
        
            | 
            | 
           79 | 
           			CyString extradir;
  | 
        
        
           | 18 | 
           cycrow | 
           80 | 
           			s_int type = SPK::GetAutomaticFiletype(str->str, &extradir, false);
  | 
        
        
           | 1 | 
           cycrow | 
           81 | 
              | 
        
        
            | 
            | 
           82 | 
           			if ( type == FILETYPE_EXTRA && !extradir.Empty() )
  | 
        
        
            | 
            | 
           83 | 
           				str->data = CyString::Number(type) + " " + extradir;
  | 
        
        
            | 
            | 
           84 | 
           			else
  | 
        
        
            | 
            | 
           85 | 
           				str->data = CyString::Number(type);
  | 
        
        
            | 
            | 
           86 | 
           		}
  | 
        
        
            | 
            | 
           87 | 
           	}
  | 
        
        
            | 
            | 
           88 | 
              | 
        
        
            | 
            | 
           89 | 
           	CyString GetSizeString ( unsigned long lSize)
  | 
        
        
            | 
            | 
           90 | 
           	{
  | 
        
        
            | 
            | 
           91 | 
           		float size = (float)lSize;
  | 
        
        
            | 
            | 
           92 | 
              | 
        
        
            | 
            | 
           93 | 
           		int level = 0;
  | 
        
        
            | 
            | 
           94 | 
           		while ( size > 1000 )
  | 
        
        
            | 
            | 
           95 | 
           		{
  | 
        
        
            | 
            | 
           96 | 
           			size /= 1024;
  | 
        
        
            | 
            | 
           97 | 
           			++level;
  | 
        
        
            | 
            | 
           98 | 
           			if ( level >= 3 )
  | 
        
        
            | 
            | 
           99 | 
           				break;
  | 
        
        
            | 
            | 
           100 | 
           		}
  | 
        
        
            | 
            | 
           101 | 
              | 
        
        
            | 
            | 
           102 | 
           		CyString s;
  | 
        
        
            | 
            | 
           103 | 
           		char str[20];
  | 
        
        
            | 
            | 
           104 | 
           		switch ( level )
  | 
        
        
            | 
            | 
           105 | 
           		{
  | 
        
        
            | 
            | 
           106 | 
           			case 0:
  | 
        
        
            | 
            | 
           107 | 
           				SPRINTF(str, "%.0f"), size );
  | 
        
        
            | 
            | 
           108 | 
           				s = str;
  | 
        
        
            | 
            | 
           109 | 
           				s += "B";
  | 
        
        
            | 
            | 
           110 | 
           				break;
  | 
        
        
            | 
            | 
           111 | 
           			case 1:
  | 
        
        
            | 
            | 
           112 | 
           				SPRINTF(str, "%.2f"), size );
  | 
        
        
            | 
            | 
           113 | 
           				s = str;
  | 
        
        
            | 
            | 
           114 | 
           				s += "KB";
  | 
        
        
            | 
            | 
           115 | 
           				break;
  | 
        
        
            | 
            | 
           116 | 
           			case 2:
  | 
        
        
            | 
            | 
           117 | 
           				SPRINTF(str, "%.2f"), size );
  | 
        
        
            | 
            | 
           118 | 
           				s = str;
  | 
        
        
            | 
            | 
           119 | 
           				s += "MB";
  | 
        
        
            | 
            | 
           120 | 
           				break;
  | 
        
        
            | 
            | 
           121 | 
           			case 3:
  | 
        
        
            | 
            | 
           122 | 
           				SPRINTF(str, "%.3f"), size );
  | 
        
        
            | 
            | 
           123 | 
           				s = str;
  | 
        
        
            | 
            | 
           124 | 
           				s += "GB";
  | 
        
        
            | 
            | 
           125 | 
           				break;
  | 
        
        
            | 
            | 
           126 | 
           		}
  | 
        
        
            | 
            | 
           127 | 
           		return s;
  | 
        
        
            | 
            | 
           128 | 
           	}
  | 
        
        
            | 
            | 
           129 | 
              | 
        
        
            | 
            | 
           130 | 
           	bool WriteScriptStyleSheet(CyString dest)
  | 
        
        
            | 
            | 
           131 | 
           	{
  | 
        
        
            | 
            | 
           132 | 
           		CyStringList list;
  | 
        
        
            | 
            | 
           133 | 
           		list.PushBack("<?xml version=\"1.0\" ?>");
  | 
        
        
            | 
            | 
           134 | 
           		list.PushBack("<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >");
  | 
        
        
            | 
            | 
           135 | 
           		list.PushBack("<xsl:template match=\"/\">");
  | 
        
        
            | 
            | 
           136 | 
           		list.PushBack("<html>");
  | 
        
        
            | 
            | 
           137 | 
           		list.PushBack("<head>");
  | 
        
        
            | 
            | 
           138 | 
           		list.PushBack("<title>X3TC Script: <xsl:value-of select=\"script/name\"/></title>");
  | 
        
        
            | 
            | 
           139 | 
           		list.PushBack("</head>");
  | 
        
        
            | 
            | 
           140 | 
           		list.PushBack("<body style=\"color:white;background-color:black\">");
  | 
        
        
            | 
            | 
           141 | 
           		list.PushBack("<xsl:apply-templates/>");
  | 
        
        
            | 
            | 
           142 | 
           		list.PushBack("</body>");
  | 
        
        
            | 
            | 
           143 | 
           		list.PushBack("</html>");
  | 
        
        
            | 
            | 
           144 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           145 | 
           		list.PushBack("<xsl:template match=\"script\">");
  | 
        
        
            | 
            | 
           146 | 
           		list.PushBack("<h1>Script <xsl:value-of select=\"name\"/></h1>");
  | 
        
        
            | 
            | 
           147 | 
           		list.PushBack("Version: <xsl:value-of select=\"version\"/><br/>");
  | 
        
        
            | 
            | 
           148 | 
           		list.PushBack("for Script Engine Version: <xsl:value-of select=\"engineversion\"/><br/>");
  | 
        
        
            | 
            | 
           149 | 
           		list.PushBack("<h3>Description</h3>");
  | 
        
        
            | 
            | 
           150 | 
           		list.PushBack("<xsl:value-of select=\"description\"/>");
  | 
        
        
            | 
            | 
           151 | 
           		list.PushBack("<xsl:apply-templates/>");
  | 
        
        
            | 
            | 
           152 | 
           		list.PushBack("<xsl:choose><xsl:when test=\"signature\"><br/>signed</xsl:when></xsl:choose>");
  | 
        
        
            | 
            | 
           153 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           154 | 
           		list.PushBack("<xsl:template match=\"name\">");
  | 
        
        
            | 
            | 
           155 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           156 | 
           		list.PushBack("<xsl:template match=\"version\">");
  | 
        
        
            | 
            | 
           157 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           158 | 
           		list.PushBack("<xsl:template match=\"engineversion\">");
  | 
        
        
            | 
            | 
           159 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           160 | 
           		list.PushBack("<xsl:template match=\"description\">");
  | 
        
        
            | 
            | 
           161 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           162 | 
           		list.PushBack("<xsl:template match=\"arguments\">");
  | 
        
        
            | 
            | 
           163 | 
           		list.PushBack("<h3>Arguments</h3>");
  | 
        
        
            | 
            | 
           164 | 
           		list.PushBack("<ul>");
  | 
        
        
            | 
            | 
           165 | 
           		list.PushBack("<xsl:apply-templates/>");
  | 
        
        
            | 
            | 
           166 | 
           		list.PushBack("</ul>");
  | 
        
        
            | 
            | 
           167 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           168 | 
           		list.PushBack("<xsl:template match=\"argument\">");
  | 
        
        
            | 
            | 
           169 | 
           		list.PushBack("<li>");
  | 
        
        
            | 
            | 
           170 | 
           		list.PushBack("<xsl:value-of select=\"@index\"/>: <xsl:value-of select=\"@name\"/> , <xsl:value-of select=\"@type\"/> , '<xsl:value-of select=\"@desc\"/>'");
  | 
        
        
            | 
            | 
           171 | 
           		list.PushBack("</li>");
  | 
        
        
            | 
            | 
           172 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           173 | 
           		list.PushBack("<xsl:template match=\"sourcetext\">");
  | 
        
        
            | 
            | 
           174 | 
           		list.PushBack("<h3>Source Text</h3>");
  | 
        
        
            | 
            | 
           175 | 
           		list.PushBack("<div style=\"color:white;background-color:darkgray\">");
  | 
        
        
            | 
            | 
           176 | 
           		list.PushBack("<br/>");
  | 
        
        
            | 
            | 
           177 | 
           		list.PushBack("<code>");
  | 
        
        
            | 
            | 
           178 | 
           		list.PushBack("<xsl:apply-templates/>");
  | 
        
        
            | 
            | 
           179 | 
           		list.PushBack("</code>");
  | 
        
        
            | 
            | 
           180 | 
           		list.PushBack("<br/>");
  | 
        
        
            | 
            | 
           181 | 
           		list.PushBack("</div>");
  | 
        
        
            | 
            | 
           182 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           183 | 
           		list.PushBack("<xsl:template match=\"line\">");
  | 
        
        
            | 
            | 
           184 | 
           		list.PushBack("<b style=\"color:blue\"><xsl:value-of select=\"@linenr\"/> <xsl:choose><xsl:when test=\"@interruptable\"><b style=\"color:cyan\"><xsl:value-of select=\"@interruptable\"/></b></xsl:when><xsl:otherwise> </xsl:otherwise></xsl:choose></b> <b style=\"color:#777777\"><xsl:value-of select=\"translate(@indent,' ','|ÿ')\"/></b><xsl:apply-templates/><br/>");
  | 
        
        
            | 
            | 
           185 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           186 | 
           		list.PushBack("<xsl:template match=\"text\">");
  | 
        
        
            | 
            | 
           187 | 
           		list.PushBack("<xsl:value-of select=\".\"/>");
  | 
        
        
            | 
            | 
           188 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           189 | 
           		list.PushBack("<xsl:template match=\"var\">");
  | 
        
        
            | 
            | 
           190 | 
           		list.PushBack("<b style=\"color:darkgreen\">");
  | 
        
        
            | 
            | 
           191 | 
           		list.PushBack("<xsl:value-of select=\".\"/>");
  | 
        
        
            | 
            | 
           192 | 
           		list.PushBack("</b>");
  | 
        
        
            | 
            | 
           193 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           194 | 
           		list.PushBack("<xsl:template match=\"comment\"><b style=\"color:black\"><xsl:value-of select=\".\"/></b></xsl:template>");
  | 
        
        
            | 
            | 
           195 | 
           		list.PushBack("<xsl:template match=\"call\">'<a><xsl:attribute name=\"href\"><xsl:value-of select=\".\"/>.xml</xsl:attribute><xsl:value-of select=\".\"/></a>'</xsl:template>");
  | 
        
        
            | 
            | 
           196 | 
           		list.PushBack("<xsl:template match=\"codearray\">");
  | 
        
        
            | 
            | 
           197 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           198 | 
           		list.PushBack("<xsl:template match=\"signature\">");
  | 
        
        
            | 
            | 
           199 | 
           		list.PushBack("</xsl:template>");
  | 
        
        
            | 
            | 
           200 | 
           		list.PushBack("</xsl:stylesheet>");
  | 
        
        
            | 
            | 
           201 | 
              | 
        
        
            | 
            | 
           202 | 
           		CFileIO File(dest + "/x2script.xsl");
  | 
        
        
            | 
            | 
           203 | 
           		return File.WriteFile(&list);
  | 
        
        
            | 
            | 
           204 | 
           	}
  | 
        
        
            | 
            | 
           205 | 
              | 
        
        
            | 
            | 
           206 | 
           	CyString ConvertTimeString(time_t time)
  | 
        
        
            | 
            | 
           207 | 
           	{
  | 
        
        
            | 
            | 
           208 | 
           		struct tm   *currDate;
  | 
        
        
            | 
            | 
           209 | 
           		char    dateString[100];
  | 
        
        
            | 
            | 
           210 | 
              | 
        
        
            | 
            | 
           211 | 
           		time_t n = time;
  | 
        
        
            | 
            | 
           212 | 
           		currDate = localtime(&n);
  | 
        
        
            | 
            | 
           213 | 
           		strftime(dateString, sizeof dateString, "(%d/%m/%Y) %H:%M", currDate);
  | 
        
        
            | 
            | 
           214 | 
              | 
        
        
            | 
            | 
           215 | 
           		return CyString(dateString);
  | 
        
        
            | 
            | 
           216 | 
           	}
  | 
        
        
            | 
            | 
           217 | 
              | 
        
        
            | 
            | 
           218 | 
           	CyString FormatTextName(int id, int lang, bool newstyle)
  | 
        
        
            | 
            | 
           219 | 
           	{
  | 
        
        
            | 
            | 
           220 | 
           		if ( newstyle )
  | 
        
        
            | 
            | 
           221 | 
           			return CyString::Number(id).PadNumber(4) + "-L" + CyString::Number(lang).PadNumber(3);
  | 
        
        
            | 
            | 
           222 | 
           		else
  | 
        
        
            | 
            | 
           223 | 
           			return CyString::Number(lang) + CyString::Number(id).PadNumber(4);
  | 
        
        
            | 
            | 
           224 | 
           	}
  | 
        
        
            | 
            | 
           225 | 
           };
  |