Beispiel #1
0
int main(int argc, char *argv[])
{
	if (argc != 2)
	{
		printf("arc_unpacker by Fuyin\n");
		printf("usage: %s <input.arc>\n", argv[0]);
		return -1;
	}

	std::string in_filename = argv[1];
	FILE *fin = fopen(in_filename.c_str(), "rb");
	if (!fin)
	{
		printf("open input file error!\n");
		return -1;
	}

	std::string dirname = in_filename.substr(0, in_filename.find("."));
	_mkdir(dirname.c_str());

	DWORD arc_size = 0;
	fseek(fin, 0, SEEK_END);
	arc_size = ftell(fin);
	fseek(fin, 0, SEEK_SET);

	BYTE *arcdata = new BYTE[arc_size];
	fread(arcdata, arc_size, 1, fin);
	BYTE *buffer = arcdata;

	arc_header *header = (arc_header*)buffer;
	buffer += sizeof(arc_header);

	if (strncmp(header->magic, "BURIKO ARC20", 0xC))
	{
		printf("format not match!\n");
		return -1;
	}

	DWORD file_count = header->entry_count;
	//DWORD baseoffset = sizeof(arc_header)+file_count*sizeof(arc_entry);

	arc_entry *entry = (arc_entry*)buffer;
	buffer += file_count*sizeof(arc_entry);

	BYTE *filedata = (BYTE*)buffer;

	for (DWORD i = 0; i < file_count; i++)
	{
		std::string out_filename = dirname + "\\" + entry[i].filename;
		FILE* fout = fopen(out_filename.c_str(), "wb");
		if (!fout)
		{
			printf("open output file error!\n");
			return -1;
		}

		fwrite(&filedata[entry[i].offset], entry[i].size, 1, fout);
		fclose(fout);
	}

	delete[]arcdata;
	fclose(fin);
	return 0;
}
Beispiel #2
0
/*
	save archive into disk files.
*/
bool CInMemoryBuffer::flushToDisk()
{
	archive_hdr_t * hdr;
	archive_index_table_item_t * index;
	archive_item_t * itemPointer;
	//hislog_key_t * tm = &startTime;
	
	__uint i;
	hislog_stream_list::iterator it;
	__uint valueCount;
	__uint fileSize;
	CSharedMemory shm;

	//utils_debug("flush to disk begin - %s\n", m_fileName.c_str());

	//utils_debug("rlock 7\n");
	//ReadLock();
	WriteLock();

	if(m_state != bs_ready){
		//utils_debug("release 14\n");
		Release();
		throw(m_state);
	}
	
	// estimate size needed
	i = m_streams.size();
	it = m_streams.begin();
	valueCount = 0;
	for(; i; i--, it++){
		valueCount += it->second->m_values.size();
	}
	if(!valueCount){
		//utils_debug("release 15\n");
		Release();
		return false;
	}

	fileSize  = sizeof(archive_hdr_t);
	fileSize += m_streams.size() * sizeof(archive_index_table_item_t);
	fileSize += valueCount * sizeof(archive_item_t);	

	_mkdir(m_pathName.c_str());
	shm.StaticInit(
		m_fileName.c_str(),
		0,
		fileSize,
		NULL,
		OPEN_ALWAYS,
		FILE_SHARE_READ,
		GENERIC_READ | GENERIC_WRITE
		);
	if(!(PVOID)shm){
		//utils_debug("release 16\n");
		Release();
		return false;
	}

	// relocate pointers
	hdr = (archive_hdr_t*)((PVOID)shm);
	index = (archive_index_table_item_t*)(hdr + 1);
	itemPointer = (archive_item_t*)(index + m_streams.size());
	
	memset(hdr, 0, sizeof(hdr));
	hdr->version = ARCHIVER_VERSION;
	hdr->tagCount = m_streams.size();
	hdr->valueCount = valueCount;
	hdr->startTime = m_startTime;
	hdr->endTime = m_endTime;
	
	i = m_streams.size();
	it = m_streams.begin();
	for(; i; i--, it++){
		valueCount = it->second->flush((__u8*)itemPointer, NULL, NULL);
		index->dataOffset = (__u8*)itemPointer - (__u8*)hdr;
		index->tagName = it->second->m_name;
		index->valueCount = valueCount;
		itemPointer += valueCount;
		index++;
	}

	assert((__u8*)itemPointer == (__u8*)hdr + fileSize);
	
	// ok, this last write will mark the file as a valid archive
	hdr->magic = ARCHIVE_MAGIC;

	m_state = bs_ready;
	
	//utils_debug("release 17\n");
	Release();
	
	shm.UnInit();
	
	//utils_debug("flush to disk end - %s\n", m_fileName.c_str());

	return true;
}
Beispiel #3
0
void __fastcall TFileLoadSave::FileNameChange(TObject *Sender)
{
	if (	!FileName->Text.IsEmpty()
		&&	FileName->SelStart
		&& strrchr(" ]})[{(,;:+=/<>.#",FileName->Text[FileName->SelStart]))
	{
		char work[20];
		strcpy(work,FileName->Text.c_str());
		int i=FileName->SelStart-1;
		strcpy(work+i,work+i+1);
		FileName->Text=work;
		FileName->SelStart=i;
	}

	if (!FileName->Text.IsEmpty())
		if (FileName->Text[1]=='*'	||	FileName->Text[2]=='*')
			FileName->Text="";

	if (!FileName->Text.IsEmpty())
	{
		char work[20];
		if (FileName->Text[1]=='[')
		{
			strcpy(work,FileName->Text.c_str());
			work[strlen(work)-1]=0;
			FileName->Text=work+1;
		}

		strcpy(work,FileName->Text.c_str());
		char*	finddot=work;
		while (*finddot!='.' && *finddot!=0)
			finddot++;
		if (*finddot)
		{
			*finddot=0;
			FileName->Text=work;
		}
	}
	if (FileName->Text.IsEmpty())
	{
		Panel2->Caption="";
		Able(Save,false);
		Able(New,false);
		Able(Rename,false);
		Able(Name,false);
		Able(Open,false);
		Title->Enabled=false;
		char buff[50];
		LoadString(HInstance,TEXT_FILE_0LEN,buff,50);
		Title->Text=buff;
		return;

	}
	else
	if (FileName->Text[1]>='0' && FileName->Text[1]<='9')
	{
		Able(Save,false);
		Able(New,false);
		Able(Rename,false);
		Able(Name,false);
		Able(Open,false);
		Title->Enabled=false;
		char buff[50];
		LoadString(HInstance,TEXT_FILE_DIGIT,buff,50);
		Title->Text=buff;
		return;
	}
	if (dirmode)
	{
		char pathname[100];
		strcpy(pathname,FileListBox1->Directory.c_str());
		strcat(pathname,"\\");
		char buff[12];
		strcpy(buff,FileName->Text.c_str());
		if (	FileName->Text[1]==ext[0]
			||	FileName->Text[1]==ext[1]
			)
		{
			FileName->Text=buff+1;
		}

		if (ext[0]=='c' || strcmpi(buff,"DEFAULT"))
		{
			strcat(pathname,ext+1);
			Panel2->Caption=ext+1;
		}
		else
			Panel2->Caption="";
		FileName->MaxLength=7;

		strcat(pathname,FileName->Text.c_str());
		if (!_mkdir(pathname))
		{
			_rmdir(pathname);
			Able(New,true);
			Able(Rename,true);
			Able(Name,true);
			Able(Open,false);
			if (ext[0]=='c')
				Title->Enabled=true;
			else
				Title->Enabled=false;
			Title->Text=InputTitle;
		}
		else
		{
			Able(New,false);
			Able(Rename,false);
			Able(Name,false);
			strcat(pathname,"\\direxist.tst");
			Title->Enabled=false;
			Title->Text="";
			FILE* F=fopen(pathname,"wb");
			if (F)
			{
				fclose(F);
				remove(pathname);
				Able(Open,true);
				pathname[strlen(pathname)-13]=0;
				strcat(pathname,"\\campaign.def");
				F=fopen(pathname,"rb");
				if (F)
				{
 //					MeCampaignTexts tmp;
   //					fread(&tmp,sizeof(tmp),1,F);
	 //				fclose(F);
	   //				Title->Enabled=false;
		 //			Title->Text=tmp.title;
				}
			}
			else
			{
				Title->Enabled=false;
				char buff[50];
				LoadString(HInstance,TEXT_FILE_ILLEGAL,buff,50);
				Title->Text=buff;
				Able(Open,false);
			}
		}
	}
	else
	{
		char pathname[100];
		strcpy(pathname,FileListBox1->Directory.c_str());
		strcat(pathname,"\\");
		strcat(pathname,FileName->Text.c_str());
		strcat(pathname,ext);
		FILE* F=fopen(pathname,"rb");
		if (F)
		{
			fclose(F);
			Title->Enabled=false;
			if (*(ULong*)ext==*(ULong*)".BF")
			{
				if (fakedir)
					FILEMAN.fakedir(FIL_USERMISSION1,FileListBox1->Directory.c_str());
				strcpy(pathname,FileName->Text.c_str());
				strcat(pathname,ext);
                Persons4	Persons_2;
//				Persons_2.justscanning=true;
				Persons_2.LoadSubPiece(NULL,FILEMAN.fakefile(FIL_USERMISSION1,pathname),(int)Persons2::LOADEDBFS-1,Persons2::SCANNAMES);
  //				Persons_2.justscanning=false;
				Title->Text="";//Persons_2.bfdesc->title;
			}
			else
				Title->Text="";
			if (Save->Visible)
				Title->Enabled=true;
			else
				Title->Enabled=false;
			Able(Open,true);
			Able(New,false);
			Able(Rename,false);
			Able(Name,false);
			if (FileName->Enabled)
				Able(Save,false);
			else
				Able(Save,true);
		}
		else
		{
			F=fopen(pathname,"wb");
			if (F)
			{
				fclose(F);
				remove(pathname);

				Able(Save,true);
				Able(New,true);
				Able(Rename,true);
				Able(Name,true);
				Able(Open,false);
				Title->Text=InputTitle;
				Title->Enabled=true;
			}
			else
			{
				Able(Save,false);
				Able(New,false);
				Able(Rename,false);
				Able(Name,false);
				Able(Open,false);
				char buff[50];
				LoadString(HInstance,TEXT_FILE_ILLEGAL,buff,50);
				Title->Text=buff;
				Title->Enabled=false;
			}
		}
	}
}
Beispiel #4
0
kint kvfs_mkdir(const kchar *a_path)
{
	return _mkdir(a_path);
}
Beispiel #5
0
int PatchMonsterModel (char *modelname)
{
	cvar_t		*gamedir;
	int			j;
	int			numskins;			// number of skin entries
	char		skins[MAX_SKINS][MAX_SKINNAME];	// skin entries
	char		infilename[MAX_OSPATH];
	char		outfilename[MAX_OSPATH];
	char		*p;
	FILE		*infile;
	FILE		*outfile;
	dmdl_t		model;				// model header
	byte		*data;				// model data
	int			datasize;			// model data size (bytes)
	int			newoffset;			// model data offset (after skins)
	qboolean	is_tank=false;
	qboolean	is_soldier=false;

	// get game (moddir) name
	gamedir = gi.cvar("game", "", 0);
	if (!*gamedir->string)
		return 0;	// we're in baseq2

	Com_sprintf (outfilename, sizeof(outfilename), "%s/%s", gamedir->string, modelname);
	if (outfile = fopen (outfilename, "rb"))
	{
		// output file already exists, move along
		fclose (outfile);
		return 0;
	}


	numskins = 8;
	// special cases
	if(!strcmp(modelname,"models/monsters/tank/tris.md2"))
	{
		is_tank = true;
		numskins = 16;
	}
	else if(!strcmp(modelname,"models/monsters/soldier/tris.md2"))
	{
		is_soldier = true;
		numskins = 24;
	}

	for (j=0; j<numskins; j++)
	{
		memset (skins[j], 0, MAX_SKINNAME);
	//	strncpy( skins[j], modelname );
		Q_strncpyz( skins[j], modelname, sizeof(skins[j]) );
		p = strstr( skins[j], "tris.md2" );
		if(!p)
		{
			fclose (outfile);
			gi.dprintf( "Error patching %s\n",modelname);
			return 0;
		}
		*p = 0;
		if(is_soldier)
		{
			switch (j) {
			case 0:
				strcat (skins[j], "skin_lt.pcx"); break;
			case 1:
				strcat (skins[j], "skin_ltp.pcx"); break;
			case 2:
				strcat (skins[j], "skin.pcx"); break;
			case 3:
				strcat (skins[j], "pain.pcx"); break;
			case 4:
				strcat (skins[j], "skin_ss.pcx"); break;
			case 5:
				strcat (skins[j], "skin_ssp.pcx"); break;
			case 6:
				strcat (skins[j], "custom1_lt.pcx"); break;
			case 7:
				strcat (skins[j], "custompain1_lt.pcx"); break;
			case 8:
				strcat (skins[j], "custom1.pcx"); break;
			case 9:
				strcat (skins[j], "custompain1.pcx"); break;
			case 10:
				strcat (skins[j], "custom1_ss.pcx"); break;
			case 11:
				strcat (skins[j], "custompain1_ss.pcx"); break;
			case 12:
				strcat (skins[j], "custom2_lt.pcx"); break;
			case 13:
				strcat (skins[j], "custompain2_lt.pcx"); break;
			case 14:
				strcat (skins[j], "custom2.pcx"); break;
			case 15:
				strcat (skins[j], "custompain2.pcx"); break;
			case 16:
				strcat (skins[j], "custom2_ss.pcx"); break;
			case 17:
				strcat (skins[j], "custompain2_ss.pcx"); break;
			case 18:
				strcat (skins[j], "custom3_lt.pcx"); break;
			case 19:
				strcat (skins[j], "custompain3_lt.pcx"); break;
			case 20:
				strcat (skins[j], "custom3.pcx"); break;
			case 21:
				strcat (skins[j], "custompain3.pcx"); break;
			case 22:
				strcat (skins[j], "custom3_ss.pcx"); break;
			case 23:
				strcat (skins[j], "custompain3_ss.pcx"); break;
			}
		}
		else if(is_tank)
		{
			switch (j) {
			case 0:
				strcat (skins[j], "skin.pcx"); break;
			case 1:
				strcat (skins[j], "pain.pcx"); break;
			case 2:
				strcat (skins[j], "../ctank/skin.pcx"); break;
			case 3:
				strcat (skins[j], "../ctank/pain.pcx"); break;
			case 4:
				strcat (skins[j], "custom1.pcx"); break;
			case 5:
				strcat (skins[j], "custompain1.pcx"); break;
			case 6:
				strcat (skins[j], "../ctank/custom1.pcx"); break;
			case 7:
				strcat (skins[j], "../ctank/custompain1.pcx"); break;
			case 8:
				strcat (skins[j], "custom2.pcx"); break;
			case 9:
				strcat (skins[j], "custompain2.pcx"); break;
			case 10:
				strcat (skins[j], "../ctank/custom2.pcx"); break;
			case 11:
				strcat (skins[j], "../ctank/custompain2.pcx"); break;
			case 12:
				strcat (skins[j], "custom3.pcx"); break;
			case 13:
				strcat (skins[j], "custompain3.pcx"); break;
			case 14:
				strcat (skins[j], "../ctank/custom3.pcx"); break;
			case 15:
				strcat (skins[j], "../ctank/custompain3.pcx"); break;
			}
		}
		else
		{
			switch (j) {
			case 0:
				strcat (skins[j], "skin.pcx"); break;
			case 1:
				strcat (skins[j], "pain.pcx"); break;
			case 2:
				strcat (skins[j], "custom1.pcx"); break;
			case 3:
				strcat (skins[j], "custompain1.pcx"); break;
			case 4:
				strcat (skins[j], "custom2.pcx"); break;
			case 5:
				strcat (skins[j], "custompain2.pcx"); break;
			case 6:
				strcat (skins[j], "custom3.pcx"); break;
			case 7:
				strcat (skins[j], "custompain3.pcx"); break;
			}
		}
	}

	// load original model
	Com_sprintf (infilename, sizeof(infilename), "baseq2/%s", modelname);
	if ( !(infile = fopen (infilename, "rb")) )
	{
		// If file doesn't exist on user's hard disk, it must be in 
		// pak0.pak

		pak_header_t	pakheader;
		pak_item_t		pakitem;
		FILE			*fpak;
		int				k, numitems;

		fpak = fopen("baseq2/pak0.pak","rb");
		if(!fpak)
		{
			cvar_t	*cddir;
			char	pakfile[MAX_OSPATH];

			cddir = gi.cvar("cddir", "", 0);
			Com_sprintf(pakfile, sizeof(pakfile), "%s/baseq2/pak0.pak",cddir->string);
			fpak = fopen(pakfile,"rb");
			if(!fpak)
			{
				gi.dprintf("PatchMonsterModel: Cannot find pak0.pak\n");
				return 0;
			}
		}
		fread(&pakheader,1,sizeof(pak_header_t),fpak);
		numitems = pakheader.dsize/sizeof(pak_item_t);
		fseek(fpak,pakheader.dstart,SEEK_SET);
		data = NULL;
		for(k=0; k<numitems && !data; k++)
		{
			fread(&pakitem,1,sizeof(pak_item_t),fpak);
			if(!Q_stricmp(pakitem.name,modelname))
			{
				fseek(fpak,pakitem.start,SEEK_SET);
				fread(&model, sizeof(dmdl_t), 1, fpak);
				datasize = model.ofs_end - model.ofs_skins;
				if ( !(data = malloc (datasize)) )	// make sure freed locally
				{
					fclose(fpak);
					gi.dprintf ("PatchMonsterModel: Could not allocate memory for model\n");
					return 0;
				}
				fread (data, sizeof (byte), datasize, fpak);
			}
		}
		fclose(fpak);
		if(!data)
		{
			gi.dprintf("PatchMonsterModel: Could not find %s in baseq2/pak0.pak\n",modelname);
			return 0;
		}
	}
	else
	{
		fread (&model, sizeof (dmdl_t), 1, infile);
	
		datasize = model.ofs_end - model.ofs_skins;
		if ( !(data = malloc (datasize)) )	// make sure freed locally
		{
			gi.dprintf ("PatchMonsterModel: Could not allocate memory for model\n");
			return 0;
		}
		fread (data, sizeof (byte), datasize, infile);
	
		fclose (infile);
	}
	
	// update model info
	model.num_skins = numskins;
	
	newoffset = numskins * MAX_SKINNAME;
	model.ofs_st     += newoffset;
	model.ofs_tris   += newoffset;
	model.ofs_frames += newoffset;
	model.ofs_glcmds += newoffset;
	model.ofs_end    += newoffset;
	
	// save new model
	Com_sprintf (outfilename, sizeof(outfilename), "%s/models", gamedir->string);	// make some dirs if needed
	_mkdir (outfilename);
	strcat (outfilename,"/monsters");
	_mkdir (outfilename);
	Com_sprintf (outfilename, sizeof(outfilename), "%s/%s", gamedir->string, modelname);
	p = strstr(outfilename,"/tris.md2");
	*p = 0;
	_mkdir (outfilename);

	Com_sprintf (outfilename, sizeof(outfilename), "%s/%s", gamedir->string, modelname);
	
	if ( !(outfile = fopen (outfilename, "wb")) )
	{
		// file couldn't be created for some other reason
		gi.dprintf ("PatchMonsterModel: Could not save %s\n", outfilename);
		free (data);
		return 0;
	}
	
	fwrite (&model, sizeof (dmdl_t), 1, outfile);
	fwrite (skins, sizeof (char), newoffset, outfile);
	fwrite (data, sizeof (byte), datasize, outfile);
	
	fclose (outfile);
	gi.dprintf ("PatchMonsterModel: Saved %s\n", outfilename);
	free (data);
	return 1;
}
Beispiel #6
0
/**
 *	計算およびDB構築
 *
 *	@param[in] n			サンプル数
 */
void EMAThread::Calcuration(int n)
{
	// 変数宣言
	QString readFileName;			// 読み込みファイル名
	QFile readFile;					// 読み込みファイル
	QString readFileLine;			// 読み込みファイル行
	QString writeFileName;			// 書き込みファイル名
	QFile writeFile;				// 書き込みファイル
	vector <PliceData> pliceData;	// 時系列データ
	double ma_open;					// MA(Open)
	double ma_high;					// MA(High)
	double ma_low;					// MA(Low)
	double ma_close;				// MA(Close)
	double ma_volume;				// MA(Volume)
	double ma_aClose;				// MA(AClose)
	double pMa_open;				// 前日のMA(Open)
	double pMa_high;				// 前日のMA(High)
	double pMa_low;					// 前日のMA(Low)
	double pMa_close;				// 前日のMA(Close)
	double pMa_volume;				// 前日のMA(Volume)
	double pMa_aClose;				// 前日のMA(AClose)
	PliceData tempData;				// 一時保存用時系列データ
	QString temp_1;					// 一時保存用文字列
	QString temp_2;					// 一時保存用文字列

	// ディレクトリ生成
	_mkdir("DB\\EMA_" + temp_1.setNum(n).toLocal8Bit());

	// 各IDについて処理実行
	for (int i = 1000; i < 1000000; i++) {
		if (((i > 10000) && !((i == 998405) || (i == 998407)))) {
			continue;
		}

		// 変数初期化
		pliceData.clear();

		// 読み込み用ファイルオープン
		readFileName = "Yahoo\\" + temp_1.setNum(i) + ".csv";
		readFile.setFileName(readFileName);
		if (readFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
			// 宣言&初期化
			QTextStream readFileReader(&readFile);
			readFileLine = "";

			// 時系列データの読み取り
			while (!readFileReader.atEnd()) {
				readFileLine = readFileReader.readLine();
				// データ取得
				if (readFileLine != "") {
					tempData.mDate		= QDate::fromString((readFileLine.split(",").at(0)), "yyyy/M/d");
					tempData.mOpen		= readFileLine.split(",").at(1).toDouble();
					tempData.mHigh		= readFileLine.split(",").at(2).toDouble();
					tempData.mLow		= readFileLine.split(",").at(3).toDouble();
					tempData.mClose		= readFileLine.split(",").at(4).toDouble();
					tempData.mVolume	= readFileLine.split(",").at(5).toDouble();
					tempData.mAClose	= readFileLine.split(",").at(6).toDouble();
					pliceData.push_back(tempData);
				}
			}

			// 書き込み用ファイルオープン
			writeFileName = "DB\\EMA_" + temp_1.setNum(n) + "\\" + temp_2.setNum(i) + ".dat";
			writeFile.setFileName(writeFileName);
			if (!writeFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
				return;
			}

			// 書き込み処理
			for (int j = n; j < (int)pliceData.size(); j++) {
				QTextStream out(&writeFile);

				// EMA計算
				ma_open		= 0;
				ma_high		= 0;
				ma_low		= 0;
				ma_close	= 0;
				ma_volume	= 0;
				ma_aClose	= 0;
				if (j == n) {
					for (int k = 0; k < n; k++) {
						ma_open		+= pliceData[j-k].mOpen;
						ma_high		+= pliceData[j-k].mHigh;
						ma_low		+= pliceData[j-k].mLow;
						ma_close	+= pliceData[j-k].mClose;
						ma_volume	+= pliceData[j-k].mVolume;
						ma_aClose	+= pliceData[j-k].mAClose;
					}
					ma_open		= ma_open / n;
					ma_high		= ma_high / n;
					ma_low		= ma_low / n;
					ma_close	= ma_close / n;
					ma_volume	= ma_volume / n;
					ma_aClose	= ma_aClose / n;
				}
				else {
					ma_open		= (pliceData[j].mOpen * 2 / (n + 1)) + (pMa_close * (n + 1 - 2) / (n + 1));
					ma_high		= (pliceData[j].mHigh * 2 / (n + 1)) + (pMa_close * (n + 1 - 2) / (n + 1));
					ma_low		= (pliceData[j].mLow * 2 / (n + 1)) + (pMa_close * (n + 1 - 2) / (n + 1));
					ma_close	= (pliceData[j].mClose * 2 / (n + 1)) + (pMa_close * (n + 1 - 2) / (n + 1));
					ma_volume	= (pliceData[j].mVolume * 2 / (n + 1)) + (pMa_close * (n + 1 - 2) / (n + 1));
					ma_aClose	= (pliceData[j].mAClose * 2 / (n + 1)) + (pMa_close * (n + 1 - 2) / (n + 1));
				}

				// EMAおよび乖離率の書き込み
				out << (pliceData[j].mDate.toString("yyyy/M/d")) << ","
					<< ma_open << ","
					<< ma_high << ","
					<< ma_low << ","
					<< ma_close << ","
					<< ma_volume << ","
					<< ma_aClose << ","
					<< (pliceData[j-1].mOpen - ma_open) / ma_open * 100 << ","
					<< (pliceData[j-1].mHigh - ma_high) / ma_high * 100 << ","
					<< (pliceData[j-1].mLow - ma_low) / ma_low * 100 << ","
					<< (pliceData[j-1].mClose - ma_close) / ma_close * 100 << ","
					<< (pliceData[j-1].mVolume - ma_volume) / ma_volume * 100 << ","
					<< (pliceData[j-1].mAClose - ma_aClose) / ma_aClose * 100 << "\n";
				pMa_open = ma_open;
				pMa_high = ma_high;
				pMa_low = ma_low;
				pMa_close = ma_close;
				pMa_volume = ma_volume;
				pMa_aClose = ma_aClose;
			}

			writeFile.close();
		}

		readFile.close();
	}
}
Beispiel #7
0
/*
==============
Sys_Mkdir
==============
*/
void Sys_Mkdir( const char *path ) {
	_mkdir (path);
}
bool manejadorArchivos::agregarExamenComplejo(QString nombre, QList<QStringList> lista)
{
// En el QStringList el primero es el nombre de la division y le siguen sus respectivos campos.

    if(!checkExamenComplejo(nombre))
    {
        cout << "[Agregar Examen Complejo] Entro a agregar ExamenComplejo " << endl;
        stringstream ss, sstmp;
        fstream archivo;
        ss << "bin\\Examenes Complejos\\" << nombre.toStdString().c_str();

        archivo.open("bin\\examenescomplejos.examen",ios::binary | ios::app | ios::out);

        if(archivo.is_open())
        {

            nombresExamenes t;
            strcpy(t.nombre,nombre.toStdString().c_str());
            archivo.write(reinterpret_cast<char *> (&t),sizeof(t));
            _mkdir(ss.str().c_str());

            sstmp<< "bin\\Examenes Complejos\\" <<nombre.toStdString() << "\\ordendivisiones.edta";
            fstream archivo3;
            cout << "SSTMP: " << sstmp.str().c_str() << endl;
            archivo3.open(sstmp.str().c_str(), ios::out | ios::binary | ios::app);

            for(int i = 0 ; i<lista.length(); i++)
            {

                ordenDivisiones oD;
                strcpy(oD.nombre,lista.at(i).at(0).toStdString().c_str());
                archivo3.write(reinterpret_cast<char *> (&oD),sizeof(oD));
                fstream archivo2;
                stringstream ss2;

                ss2 << "bin\\Examenes Complejos\\" <<nombre.toStdString() << "\\" << lista.at(i).at(0).toStdString().c_str() << ".edta";
                cout << "SS2: " << ss2.str().c_str() << endl;
                archivo2.open(ss2.str().c_str(), ios::out | ios::binary | ios::app);
                for(int j = 1; j < lista.at(i).length(); j++)
                {

                    camposExamen t;
                    strcpy(t.nombre,lista.at(i).at(j).toStdString().c_str());
                    archivo2.write(reinterpret_cast <char *> (&t), sizeof(t));
                    archivo2.close();
                }
            }
            archivo.close();
            archivo3.close();
            return true;

        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
Beispiel #9
0
VARESULT SetOptions(CCommandLine &oCmdLine, VEM_CLASS &oExport) {
/* Command-line argument parsing

	This functions sets the default model properteries, then parses the command-line
	arguments to find overiding values.
	This function returns an error if the required avatar and export filenames are not supplied
	Once all the model properties have been searched for, the properties are passed
	directly to the exporter object
*/

	// Set export defaults
	int iVerbose = VEM_TRUE;
	int iSex = UNREAL_MALE;

	// Command line argument vars
	const char *pcTemp = NULL;
	VARESULT eResult = VA_OK;
	bool bOk = true;

	// SGA filename
	if (pcTemp = oCmdLine.GetValue(1)) {
		oExport.SetOption(VEM_SGANAME, pcTemp);
	}
	else
		bOk = false;

	// Check output filename has been supplied
	if (oCmdLine.GetValue(2) == NULL)
		bOk = false;

	// Check all filenames have been specified
	if (!bOk) 
		eResult = VA_MISSING_FILENAME;

	// Model name
	if (bOk) {
		pcTemp = oCmdLine.GetValue("name");
		if (pcTemp)
			oExport.SetOption(VEM_MODELNAME, pcTemp);
		else {
			pcTemp = oCmdLine.GetValue(2);
			char pcName[STR_SIZE] = "";
			int iDir = 0;
			int iExt = strlen(pcTemp);
			int iCount = 0;
			// Strip preceeding path
			while (iCount < (iExt - 1)) {
				if (pcTemp[iCount] == '\\')
					iDir = iCount + 1;
				iCount++;
			}
			iCount = iExt;
			// Strip file extension
			while (iCount > 0) {
				if (pcTemp[iCount] == '.') {
					iExt = iCount;
					iCount = 1;
				}
				iCount--;
			}
			// Copy out the extracted model name
			iCount = iExt - iDir;
			memcpy(pcName, pcTemp + iDir, iCount);
			pcName[iCount] = 0;
			// Set the model name
			oExport.SetOption(VEM_MODELNAME, pcName);
		}
	}

	// Temp directory
	if (bOk) {
		// Get the base directory
		pcTemp = oCmdLine.GetValue("path");
		// If none specified, set the working directory
		char pcWorkingDir[STR_SIZE] = "";
		if (!pcTemp) {
			// Get the app directory
			pcTemp = g_poVAL->GetAppDir();
			if (!pcTemp)
				return VA_DIRECTORY_ERROR;

			// Create the temp path
			char pcCurrDir[STR_SIZE];
			strcpy(pcCurrDir, pcTemp);
			strcat(pcCurrDir, "sga_temp");
			if (_mkdir(pcCurrDir) == -1 )
				if (errno != EEXIST)
					return VA_DIRECTORY_ERROR;

			pcTemp = pcCurrDir;
		}
		// Find a suitable working directory
		char pcPath[STR_SIZE] = "";
		bool bFound = false;
		int iCount = 0;
		while ((!bFound) && (iCount < VEM_MAXPROCESSES)) {
			pcPath[0] = 0;
			if (pcTemp) {
				strcpy(pcPath, pcTemp);
				int iLength = strlen(pcPath);
				if (pcPath[iLength - 1] != '\\')
					strcat(pcPath, "\\");
			}
			sprintf(pcPath, "%s%d", pcPath, iCount);
			int iResult = _mkdir(pcPath);
			if (iResult == -1) {
				// Check for a valid path
				if (errno == ENOENT) {
					eResult = VA_DIRECTORY_ERROR;
					bOk = false;
					bFound = true;
				}
			}
			else
				bFound = true;
			iCount++;
		}
		// Make sure we haven't overun the max number of processes
		if (iCount == VEM_MAXPROCESSES) {
			eResult = VA_DIRECTORY_ERROR;
			bOk = false;
		}
		oExport.SetOption(VEM_DIRECTORY, pcPath);
	}

	// Set converter verbose output
	if (bOk && (oCmdLine.FindOption("0")))
		iVerbose = VEM_FALSE;
	oExport.SetOption(VEM_VERBOSE, iVerbose);

//#===--- Unreal Tournament specific options
	// Set sex
	if (bOk && (pcTemp = oCmdLine.GetValue("sex"))) {
		if (pcTemp) {
			// Check for male
			if (stricmp(pcTemp, "male") == 0)
				iSex = UNREAL_MALE;
			// Check for female
			if (stricmp(pcTemp, "female") == 0)
				iSex = UNREAL_FEMALE;
		}
	}
	oExport.SetOption(UNREAL_SEX, iSex);


	return eResult;
} // SetOptions
Beispiel #10
0
std::wstring utils::cachePath()
{
	std::string c = path+CACHE_DIR;
	int rc =_mkdir(c.c_str()); //not a must will create anyway
	return std::wstring (c.begin(),c.end());
}
Beispiel #11
0
/*
* bee_mkdir() - Attempt to create a directory with the given path
* ! This function accepts a second argument for file permissions but it is unused on Windows
* @path: the path of the new directory
* @mode: the permissions of the directory (unused on Windows)
*/
int bee_mkdir(const char* path, mode_t mode) {
	return _mkdir(path); // Return whether the directory was successfully created or not
}
// Argh! - loads id baseq2/player models, "patches" their skin links 
//         for misc_actor (all id skins, and slots for 10 custom 
//         skins), and saves them to the current moddir location
//
int PatchPlayerModels (char *modelname)
{
	cvar_t	*game;
	int		j;
	int		numskins;		// number of skin entries
	char	skins[MAX_MD2SKINS][MAX_SKINNAME];	// skin entries
	char	infilename[MAX_OSPATH];
	char	outfilename[MAX_OSPATH];
	FILE	*infile;
	FILE	*outfile;
	dmdl_t	model;		// model header
	byte	*data;		// model data
	int		datasize;	// model data size (bytes)
	int		newoffset;	// model data offset (after skins)

	// get game (moddir) name
	game = gi.cvar("game", "", 0);
	if (!*game->string)
		return 0;	// we're in baseq2

	sprintf (outfilename, "%s/players/%s/tris.md2", game->string, modelname);
	if ((outfile = fopen (outfilename, "rb")))
	{
		// output file already exists, move along
		fclose (outfile);
//		gi.dprintf ("PatchPlayerModels: Could not save %s, file already exists\n", outfilename);
		return 0;
	}

	// clear skin names (just in case)
	for (j = 0; j < MAX_MD2SKINS; j++)
		memset (skins[j], 0, MAX_SKINNAME);

	// set model-specific data
	if(!Q_strcasecmp(modelname,"male"))
	{
		numskins = 15;
		sprintf (skins[0],	"players/male/cipher.pcx");
		sprintf (skins[1],	"players/male/claymore.pcx");
		sprintf (skins[2],	"players/male/flak.pcx");
		sprintf (skins[3],	"players/male/grunt.pcx");
		sprintf (skins[4],	"players/male/howitzer.pcx");
		sprintf (skins[5],	"players/male/major.pcx");
		sprintf (skins[6],	"players/male/nightops.pcx");
		sprintf (skins[7],	"players/male/pointman.pcx");
		sprintf (skins[8],	"players/male/psycho.pcx");
		sprintf (skins[9],	"players/male/rampage.pcx");
		sprintf (skins[10], "players/male/razor.pcx");
		sprintf (skins[11], "players/male/recon.pcx");
		sprintf (skins[12], "players/male/scout.pcx");
		sprintf (skins[13], "players/male/sniper.pcx");
		sprintf (skins[14], "players/male/viper.pcx");
	}
	else if(!Q_strcasecmp(modelname,"female"))
	{
		numskins = 10;
		sprintf (skins[0],  "players/female/athena.pcx");
		sprintf (skins[1],  "players/female/brianna.pcx");
		sprintf (skins[2],  "players/female/cobalt.pcx");
		sprintf (skins[3],  "players/female/ensign.pcx");
		sprintf (skins[4],  "players/female/jezebel.pcx");
		sprintf (skins[5],  "players/female/jungle.pcx");
		sprintf (skins[6],  "players/female/lotus.pcx");
		sprintf (skins[7],  "players/female/stiletto.pcx");
		sprintf (skins[8],  "players/female/venus.pcx");
		sprintf (skins[9],  "players/female/voodoo.pcx");
	}
	else if(!Q_strcasecmp(modelname,"cyborg"))
	{
		numskins = 3;
		sprintf (skins[0],  "players/cyborg/oni911.pcx");
		sprintf (skins[1],  "players/cyborg/ps9000.pcx");
		sprintf (skins[2],  "players/cyborg/tyr574.pcx");
	}
	else
		return 0;

	// fill in 32 slots with "customXX"
	for(j=numskins; j<32; j++)
		sprintf( skins[j], "players/%s/custom%d.pcx", modelname, j-numskins+1);
	numskins = 32;

	// load original player model
	sprintf (infilename, "baseq2/players/%s/tris.md2", modelname);
	if ( !(infile = fopen (infilename, "rb")) )
		return 0;	// no player model (this shouldn't happen)
	
	fread (&model, sizeof (dmdl_t), 1, infile);
	
	datasize = model.ofs_end - model.ofs_skins;
	if ( !(data = (byte*)G_Malloc (datasize)) )	// make sure freed locally
	{
		gi.dprintf ("PatchPlayerModels: Could not allocate memory for model\n");
		return 0;
	}
	fread (data, sizeof (byte), datasize, infile);
	
	fclose (infile);
	
	// update model info
	model.num_skins = numskins;
	
	newoffset = numskins * MAX_SKINNAME;
	model.ofs_st     += newoffset;
	model.ofs_tris   += newoffset;
	model.ofs_frames += newoffset;
	model.ofs_glcmds += newoffset;
	model.ofs_end    += newoffset;
	
	// save new player model
	sprintf (outfilename, "%s/players", game->string);	// make some dirs if needed
	_mkdir (outfilename);
	sprintf (outfilename, "%s/players/%s", game->string, modelname);
	_mkdir (outfilename);
	sprintf (outfilename, "%s/players/%s/tris.md2", game->string, modelname);
	
	if ( !(outfile = fopen (outfilename, "wb")) )
	{
		// file couldn't be created for some other reason
		gi.dprintf ("PatchPlayerModels: Could not save %s\n", outfilename);
		G_Free(data);
		return 0;
	}
	
	fwrite (&model, sizeof (dmdl_t), 1, outfile);
	fwrite (skins, sizeof (char), newoffset, outfile);
	fwrite (data, sizeof (byte), datasize, outfile);
	
	fclose (outfile);
	gi.dprintf ("PatchPlayerModels: Saved %s\n", outfilename);
	G_Free(data);
	return 1;
}
Beispiel #13
0
/** => zzip_dir_creat
 *
 * If the third argument "ext" has another special meaning here, as it
 * is used to ensure that a given zip-file is created with the first entry 
 * of the ext-list appended as an extension unless the file-path already 
 * ends with a file-extension registered in the list. Therefore {"",0} 
 * matches all files and creates them as zip-archives under the given 
 * nonmodified name. (Some magic here? If the path ends in the path
 * separator then make a real directory even in the presence of ext-list?)
 *
 * This function is not yet implemented, check for #def ZZIP_NO_CREAT
 * Write-support will extend => zzip_closedir with semantics to finalize the
 * zip-archive by writing the zip-trailer and closing the archive file.
 */
ZZIP_DIR *
zzip_dir_creat_ext_io(zzip_char_t * name, int o_mode,
                      zzip_strings_t * ext, zzip_plugin_io_t io)
{
    if (! io)
        io = zzip_get_default_io();

    if (io != zzip_get_default_io())
    {
        /* the current io-structure does not contain a "write" entry,
         * and therefore this parameter is useless. Anyone to expect
         * some behavior should be warned, so here we let the function
         * fail bluntly - and leaving the recovery to the application
         */
        errno = EINVAL;
        return 0;
    }


    if (! _ZZIP_TRY)
    {
        /* not implemented - however, we respect that a null argument to 
         * zzip_mkdir and zzip_creat works, so we silently still do the mkdir 
         */
        if (! _mkdir(name, o_mode) || errno == EEXIST)
            errno = EROFS;
        return 0;
    } else
    {
#       define MAX_EXT_LEN 10
        ZZIP_DIR *dir = zzip_dir_alloc(ext);
        int name_len = strlen(name);
        dir->realname = malloc(name_len + MAX_EXT_LEN);
        if (! dir->realname)
            goto error;

        memcpy(dir->realname, name, name_len + 1);
        ___ int fd =
            __zzip_try_open(dir->realname, O_EXCL | O_TRUNC | O_WRONLY, ext,
                            io);
        if (fd != -1)
            { dir->fd = fd; return dir; }

        ___ zzip_strings_t *exx = ext;
        int exx_len;
        for (; *exx; exx++)
        {
            if ((exx_len = strlen(*exx) + 1) <= name_len &&
                ! memcmp(dir->realname + (name_len - exx_len), *exx, exx_len))
                break;          /* keep unmodified */
            exx++;
            if (*exx)
                continue;

            if (! (exx_len = strlen(*exx)) || exx_len >= MAX_EXT_LEN)
                break;
            memcpy(dir->realname + name_len, exx, exx_len);     /* append! */
        }
        ____;
        fd = (io->fd.open)(dir->realname, O_CREAT | O_TRUNC | O_WRONLY, o_mode);
        dir->realname[name_len] = '\0'; /* keep ummodified */
        if (fd != -1)
            { dir->fd = fd; return dir; }
      error:
        zzip_dir_free(dir);
        return 0;
        ____;
    }
}
Beispiel #14
0
	int WinIO::make_dir(const char* p_dir)
	{
		if(is_dir_exists(p_dir))
			return IOBase::NORMAL_SUCCESS;
		return _mkdir(p_dir) ? IOBase::NORMAL_SUCCESS : IOBase::NORMAL_FAILED;
	}
Beispiel #15
0
void fs__mkdir(uv_fs_t* req, const char* path, int mode) {
  int result = _mkdir(path);
  SET_REQ_RESULT(req, result);
}
/* CreateDirTree
 * ----------------------------------------------------------------------------
 */
UINT CFolderDialog::CreateDirTree(CHAR CONST *pPath, UINT uPos, BOOL bDirOnly)
{
    CHAR pBuffer[MAX_PATH];
    UINT uStart = uPos;

    BOOL bUNC = FALSE;

    if (pPath[uPos] == '\\' && pPath[uPos + 1] == '\\')
    {
        uPos++;
        uPos++;

        bUNC = TRUE;
    }
    else if (pPath[uPos] == '\\')
    {
        uPos++;
        uStart++;
    }

    if (pPath[uPos] == '\0')
    {
        return TRUE;
    }

    for ( ; pPath[uPos] != '\0' && pPath[uPos] != '\\'; uPos++)
    {
        ;
    }

    if (bUNC == TRUE && pPath[uPos] != '\0')
    {
        uPos++;
        for ( ; bUNC == TRUE && pPath[uPos] != '\0' && pPath[uPos] != '\\'; uPos++)
        {
            ;
        }
    }

    if (pPath[uPos] == '\0' && bDirOnly == FALSE)
    {
        return TRUE;
    }

    memcpy(pBuffer, pPath + uStart, uPos - uStart);
    pBuffer[uPos - uStart] = '\0';

    if (pBuffer[1] == ':')
    {
        // Drive spec.
        pBuffer[2] = '\\';
        pBuffer[3] = '\0';
    }
    else if (bUNC == FALSE)
    {
        // Path
        _mkdir(pBuffer);
    }

    if (_chdir(pBuffer) != 0)
    {
        return FALSE;
    }

    return CreateDirTree(pPath, uPos, bDirOnly);
}
Beispiel #17
0
int archdep_mkdir(const char *pathname, int mode)
{
    return _mkdir(pathname);
}
int split_file(void)
{
    FILE *fp_read;
    size_t BUFSIZE = 1024;
    
    char read_buf[MAX_LINE];
    char *fp_read_name = "Test.txt";
    //char *fp_write_name = "Output.txt"
    char read_string[MAX_LINE];
    char cmp1[1] = ":"; //for comparison with the sentence
    char cmp2[1] = ","; //for comparison with the sentence
    
    int count_array[MAX_LINE];
    int loop_count = 0;
    int txt_line_count = 1;

    fp_read = fopen(fp_read_name, "r");
    if (fp_read == NULL) //normal return 0, error return NULL, and the message save at errno
    {
        printf("Open the file error: %s\n", fp_read_name);
        exit(1);
    }
    setvbuf(fp_read, NULL, _IOFBF, BUFSIZE);
    
    while (fgets(read_string, MAX_LINE, fp_read) != NULL)
    {
        //printf("%s", read_string);
        if (strlen(read_string) > 28)
        {
            if (read_string[2] == cmp1[0])
            {
                if (read_string[5] == cmp1[0])
                {
                    if (read_string[8] == cmp2[0])
                    {
                        count_array[loop_count] = txt_line_count - 1; //mark the sentence start address
                        loop_count += 1;
                        //printf("%s", read_string);
                    }
                }
            }
        }
        
        txt_line_count += 1;
    }
    fclose(fp_read);
    
    count_array[loop_count] = 99999;
    
    /* open the file again to split it */
    FILE *fp_read_0, *fp_write;
    
    char write_name_demo[100];
    char *fp_write_name_demo = write_name_demo;
    
    fp_read_0 = fopen(fp_read_name, "r");
    
    if (fp_read_0 == NULL)
    {
        printf("Open the file again error: %s\n", fp_read_name);
        exit(1);
    }
    setvbuf(fp_read_0, NULL, _IOFBF, BUFSIZE);
    
    int split_loop_count = 0;
    int fgets_loop_count = 1;
    int split_address_one, split_address_two; //to save the sentence start address and end address
    int array_length = sizeof(count_array);
    
    if (!access("temp", 0)) // check the file 'temp' existed
    {
        if (_mkdir("temp") == 0) // try to mkdir the file
        {
            printf("There is no file name 'temp' and the program can't make it, please check you permissions");
        }
    }
    
    while (fgets(read_string, MAX_LINE, fp_read_0) != NULL)
    {
        
        split_address_one = count_array[split_loop_count];
        split_address_two = count_array[split_loop_count + 1];
        /* make the save file name */
        sprintf(write_name_demo, "temp/split_temp_%d", split_loop_count);
        
        fp_write = fopen(fp_write_name_demo, "a+");
        if (fp_write == NULL)
        {
            printf("fp_write error");
        }
        /* there is write the sentence in the file */
        fprintf(fp_write, "%s", read_string);
        
        fclose(fp_write);
        fgets_loop_count += 1;
        if (fgets_loop_count >= split_address_two)
        {
            split_loop_count += 1;
        }
    }
    fclose(fp_read_0);
    return split_loop_count - 1;
}
Beispiel #19
0
void ApplicationManager::play(const char *gapp) {
	FILE *fd=fopen(gapp,"rb");
	if (!fd) return; //No file/not openable
	fseek(fd,0,SEEK_END);
	long pksz=ftell(fd);
	if (pksz < 16)
		return; //Invalid file size
	struct {
		uint32_t flistOffset;
		uint32_t version;
		char signature[8];
	} PACKED tlr;
	fseek(fd,pksz - 16,SEEK_SET);
	fread(&tlr,1,16,fd);
	tlr.version = BIGENDIAN4(tlr.version);
	tlr.flistOffset = BIGENDIAN4(tlr.flistOffset);
	if ((!strncmp(tlr.signature, "GiDeRoS", 7)) && (tlr.version == 0)) {
		glog_v("GAPP-ARCH: %s", gapp);
		gvfs_setZipFile(gapp);
		char *buffer = (char *) malloc(pksz - tlr.flistOffset);
		fseek(fd,tlr.flistOffset,SEEK_SET);
		fread(buffer, 1,pksz - tlr.flistOffset,fd);
		int offset = 0;
		while (offset < (pksz - tlr.flistOffset)) {
			int plen = strlen(buffer + offset);
			if (!plen)
				break; //End of list
			uint32_t foffset=PBULONG(buffer + offset + plen + 1);
			uint32_t fsize=PBULONG(buffer + offset + plen + 1+sizeof(uint32_t));
			const char *norm = gpath_normalizeArchivePath(buffer + offset);
			gvfs_addFile(norm, 0, foffset, fsize);
			//glog_d("GAPP-FILE: %s,%d,%d", norm, foffset, fsize);
			offset += (plen + 1 + 2 * sizeof(uint32_t));
		}
		free(buffer);
	} else
		glog_w("GAPP: Invalid signature/version");
	fclose(fd);

	if (running_ == true) {
		Event event(Event::APPLICATION_EXIT);
		GStatus status;
		application_->broadcastEvent(&event, &status);
		running_ = false;
	}

	std::string gappfile=gapp;
	std::string projectName=gappfile.substr(0,gappfile.find_last_of('.')-1);


	const char* documentsDirectory;
	const char* temporaryDirectory;

	std::string dir = "/";

	std::string documents = dir + "documents"+appPath;
	std::string temporary = dir + "temporary";
	_mkdir(documents.c_str());
	_mkdir(temporary.c_str());

	glog_v("documents: %s", documents.c_str());
	glog_v("temporary: %s", temporary.c_str());

	mkdir(documents.c_str(), 0755);
	mkdir(temporary.c_str(), 0755);

	setDocumentsDirectory(documents.c_str());
	setTemporaryDirectory(temporary.c_str());
	setResourceDirectory("");

	loadProperties();
	loadLuaFiles();
}
Beispiel #20
0
s32 mkdir( u8 *path )
{
	return _mkdir( path );
}
Beispiel #21
0
int main(int argc, char* argv[]) {
#if 0
    argv[1] = "input.xib";
    argv[2] = "output.nib";
    argc = 3;
#endif

    TELEMETRY_INIT(L"AIF-47606e3a-4264-4368-8f7f-ed6ec3366dca");

    if (checkTelemetryOptIn())
    {
        TELEMETRY_ENABLE();
    }
    else
    {
        TELEMETRY_DISABLE();
    }

    std::tr2::sys::path fName(argv[1]);

    TELEMETRY_SET_INTERNAL(isMSFTInternalMachine());
    string machineID = getMachineID();
    if (!machineID.empty())
    {
        TELEMETRY_SET_MACHINEID(machineID.c_str());
    }

    TELEMETRY_EVENT_DATA(L"Xib2NibStart", fName.filename());

    pugi::xml_document doc;
    pugi::xml_parse_result result = doc.load_file(argv[1]);
    if (!result) {
        printf("Error opening %s\n", argv[1]);
        TELEMETRY_FLUSH();
        exit(2);
        return -1;
    }

    pugi::xml_node rootNode = doc.first_child();
    const char* type = getNodeAttrib(rootNode, "type");
    if (!type) {
        printf("Unable to find input type\n");
        TELEMETRY_FLUSH();
        exit(3);
        return -1;
    }
    if (strcmp(rootNode.name(), "document") == 0 && strcmp(type, "com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB") == 0) {
        if (argc < 3) {
            printf("Usage: xib2nib input.storyboard <outputdir>\n");
            TELEMETRY_FLUSH();
            exit(1);
            return -1;
        }

        struct stat st = { 0 };
        stat(argv[2], &st);
        if (!(((st.st_mode) & S_IFMT) == S_IFDIR) && _mkdir(argv[2]) != 0) {
            printf("Unable to create directory %s err=%d\n", argv[2], errno);
            return -1;
        }
        strcpy(_g_outputDirectory, argv[2]);
        ConvertStoryboard(doc);
    } else if (strstr(type, ".XIB") != NULL) {
        if (argc < 3) {
            printf("Usage: xib2nib input.xib output.nib\n");
            TELEMETRY_FLUSH();
            exit(1);
            return -1;
        }

        FILE* fpOut = fopen(argv[2], "wb");
        if (!fpOut) {
            printf("Error opening %s\n", argv[2]);
            TELEMETRY_FLUSH();
            exit(3);
            return -1;
        }

        if (strcmp(rootNode.name(), "document") == 0) {
            ConvertXIB3ToNib(fpOut, doc);
        } else {
            ConvertXIBToNib(fpOut, doc);
        }
        fclose(fpOut);
    } else {
        printf("Unable to determine input type type=\"%s\"\n", type);
        TELEMETRY_FLUSH();
        exit(4);
        return -1;
    }

    TELEMETRY_EVENT_DATA(L"Xib2NibFinish", fName.filename());

    TELEMETRY_FLUSH();

    exit(0);
}
Beispiel #22
0
void  WindowsFiles::mkdir( const std::string& path) const
{
	_mkdir(path.c_str());
}
Beispiel #23
0
int main(int argc, char *argv[])
{
	FILE *dcp,*ext;
	BYTE *compressed,*decompressed;
	unsigned long int num,tableOff,i,x,len,pointer,compsize,decsize;
	char *name;

	printf ("WinterMute Engine Unpacker by Vash v1.0.1 -vash.romhacking.it-\n\n");
	if (argc < 2) 
	{
		printf("DCP_Unpacker file.dcp\n");
		return(0);
	}

	dcp = fopen(argv[1],"rb");
	if (!dcp)
	{
		printf("Can't open %s\n",argv[1]);
		return(0);
	}

	fseek(dcp,0x80,SEEK_SET);
	fread(&tableOff,4,1,dcp);
	fseek(dcp,tableOff,SEEK_SET);
	len=fgetc(dcp);
	name=(char*)malloc(len);
	fread(name,len,1,dcp);
	_mkdir(name);
	_chdir(name);
	free(name);
	//if (ftell(dcp) % 2 != 0)
		fseek(dcp,0x01,SEEK_CUR);
	fread(&num,4,1,dcp);
	printf("Extracting %d files\n",num);
	printf("%X",ftell(dcp));
	for (i=0;i<num;i++)
	{
		len=fgetc(dcp);
		name=(char*)malloc(len);
		fread(name,len,1,dcp);
		for (x=0;x<len;x++)
		{
			name[x]=name[x]^0x44; //DirTree decrypted
		}
		ext=CreateDirTree(name);
		printf ("Extracing %s [%d on %d]\n",name,i+1,num);
		fread(&pointer,4,1,dcp);
		fread(&decsize,4,1,dcp);
		fread(&compsize,4,1,dcp);
		fseek(dcp,0x0C,SEEK_CUR); //gotta check this jump
		tableOff = ftell(dcp);
		fseek(dcp,pointer,SEEK_SET);
		if (compsize == 0x00) //not compressed
		{
			decompressed=(BYTE*)malloc(decsize);
			fread(decompressed,decsize,1,dcp);
			fwrite(decompressed,decsize,1,ext);
			free(decompressed);
		}else{
			decompressed=(BYTE*)malloc(decsize);
			compressed=(BYTE*)malloc(compsize);
			fread(compressed,compsize,1,dcp);
			uncompress(decompressed,&decsize,compressed,compsize);
			free(compressed);
			fwrite(decompressed,decsize,1,ext);
			free (decompressed);
		}
		free(name);
		fclose(ext);
		fseek(dcp,tableOff,SEEK_SET);
		//system("pause");
	}
}
Beispiel #24
0
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	if (!m_wndView.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,
	    CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST))
	{
		TRACE0("Failed to create view\n");
		return -1;
	}

	LV_COLUMN listColumn;
    TCHAR*    rgszColumns[] = { _T("序号"),
                                _T("事件")};
    listColumn.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
    listColumn.fmt = LVCFMT_LEFT;
    listColumn.cx = 50;
    listColumn.iSubItem = 0;
    listColumn.pszText = rgszColumns[0];
    m_wndView.InsertColumn(0, &listColumn);
    listColumn.iSubItem = 1;
    listColumn.pszText = rgszColumns[1];
    listColumn.cx = 680;
    m_wndView.InsertColumn(1, &listColumn);

    LV_ITEM listItem;
    listItem.mask = LVIF_TEXT|LVIF_PARAM;
	for(int i = 0; i < MAX_GET_RECORD; i++){
		listItem.iSubItem = 0;
		listItem.iItem = m_wndView.GetItemCount();
		listItem.pszText = LPSTR_TEXTCALLBACK;
		listItem.cchTextMax = 50;
		listItem.lParam = (LPARAM)i;
    
		m_wndView.InsertItem(&listItem);
		m_wndView.SetItemText(listItem.iItem,1, LPSTR_TEXTCALLBACK);
	}
		
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	string str, s1, s2, s3,s4;
	
	//str = string(get_working_dir()) + string("var");
	str = ((CMcEvtQueryApp*)AfxGetApp())->m_folder;
	str += string("/var");
	if(ENOENT == _mkdir(str.c_str())){
		CString msg;
		msg.Format("path %s not found!", str.c_str());
		//msg	= str;
		//msg += " not found!";
		MessageBox(msg);
		PostQuitMessage(0);
	}
	str = str + "/evtd";
	_mkdir(str.c_str());
	s1 = str + "/alarm";
	s2 = str + "/operate";
//	s3 = str + "/soe";
	s4 = str + "/loginfo";
	_mkdir( s1.c_str() );
	_mkdir( s2.c_str() );
//	_mkdir( s3.c_str() );
	_mkdir( s4.c_str() );
	
	alarms = new CPMCAlarms;
	if(alarms){
		alarms->initialize_r(s1.c_str(), ALARMPOOL);
	}

	operates = new CPMCOperates;
	if(operates){
		operates->initialize_r(s2.c_str(), OPERATEPOOL);
	}

//	soes = new CPMCSoes;
//	if(soes){
//		soes->initialize_r(s3.c_str(), SOEPOOL);
//	}

//	loginfos = new CPMCLoginfos;
//	if(loginfos){
//		loginfos->initialize_r(s4.c_str(), SOEPOOL);
//	}

	return 0;
}
Beispiel #25
0
void globalwindowhandler::ProcessMessage(SDL_Event* Event)
{
  int KeyPressed = 0;

#if SDL_MAJOR_VERSION == 1
  switch(Event->active.type)
#else
  switch(Event->type)
#endif
  {
#if SDL_MAJOR_VERSION == 1
   case SDL_VIDEOEXPOSE:
    graphics::BlitDBToScreen();
#else
   case SDL_WINDOWEVENT:
    switch(Event->window.event)
    {
     case SDL_WINDOWEVENT_SHOWN:
     case SDL_WINDOWEVENT_RESIZED:
     case SDL_WINDOWEVENT_RESTORED:
      graphics::BlitDBToScreen();
      break;
    }
#endif
    break;
   case SDL_QUIT:
    if(!QuitMessageHandler || QuitMessageHandler())
      exit(0);

    return;
   case SDL_KEYDOWN:
    switch(Event->key.keysym.sym)
    {
     case SDLK_RETURN:
     case SDLK_KP_ENTER:
      if(Event->key.keysym.mod & KMOD_ALT)
      {
        graphics::SwitchMode();
        return;
      }
      else
        KeyPressed = KEY_ENTER; //Event->key.keysym.unicode;

      break;
     case SDLK_DOWN:
     case SDLK_KP_2:
      KeyPressed = KEY_DOWN + 0xE000;
      break;
     case SDLK_UP:
     case SDLK_KP_8:
      KeyPressed = KEY_UP + 0xE000;
      break;
     case SDLK_RIGHT:
     case SDLK_KP_6:
      KeyPressed = KEY_RIGHT + 0xE000;
      break;
     case SDLK_LEFT:
     case SDLK_KP_4:
      KeyPressed = KEY_LEFT + 0xE000;
      break;
     case SDLK_HOME:
     case SDLK_KP_7:
      KeyPressed = KEY_HOME + 0xE000;
      break;
     case SDLK_END:
     case SDLK_KP_1:
      KeyPressed = KEY_END + 0xE000;
      break;
     case SDLK_PAGEUP:
     case SDLK_KP_9:
      KeyPressed = KEY_PAGE_UP + 0xE000;
      break;
     case SDLK_KP_3:
     case SDLK_PAGEDOWN:
      KeyPressed = KEY_PAGE_DOWN + 0xE000;
      break;
     case SDLK_KP_5:
      KeyPressed = '.';
      break;
     case SDLK_SYSREQ:
     case SDLK_PRINTSCREEN:
      if(!ScrshotDirectoryName.IsEmpty())
      {
#ifdef WIN32
        _mkdir(ScrshotDirectoryName.CStr());
#endif
#ifdef LINUX
        mkdir(ScrshotDirectoryName.CStr(), S_IRWXU|S_IRWXG);
#endif
        DOUBLE_BUFFER->Save(ScrshotNameHandler());
      }
      return;
#if SDL_MAJOR_VERSION == 2
     /* event are now splitted between SDL_KEYDOWN and SDL_TEXTINPUT,
        all managed events must be explicited */
     case SDLK_ESCAPE:
     case SDLK_BACKSPACE:
      KeyPressed = Event->key.keysym.sym;
      break;
#endif

     case SDLK_e:
      if(Event->key.keysym.mod & KMOD_ALT
         && (Event->key.keysym.mod & KMOD_LCTRL
             || Event->key.keysym.mod & KMOD_RCTRL))
      {
        KeyPressed = '\177';
        break;
      }
     default:
#if SDL_MAJOR_VERSION == 1
      KeyPressed = Event->key.keysym.unicode;
#endif

      if(!KeyPressed)
        return;
    }
    if(std::find(KeyBuffer.begin(), KeyBuffer.end(), KeyPressed)
       == KeyBuffer.end())
      KeyBuffer.push_back(KeyPressed);
    break;
#if SDL_MAJOR_VERSION == 2
   case SDL_TEXTINPUT:
    KeyPressed = Event->text.text[0];
    if(std::find(KeyBuffer.begin(), KeyBuffer.end(), KeyPressed)
       == KeyBuffer.end())
      KeyBuffer.push_back(KeyPressed);
#endif
  }
}
Beispiel #26
0
int main(int argc, char** argv) {
	if (argc != 11) {
		printf("%s c c_reg min sigma hie_num start_fr end_fr input output\n", argv[0]);
		printf("       c --> value for the threshold function in over-segmentation\n");
		printf("   c_reg --> value for the threshold function in hierarchical region segmentation\n");
		printf("     min --> enforced minimum supervoxel size\n");
		printf("   sigma --> variance of the Gaussian smoothing.\n");
		printf("   range --> number of frames as one subsequence (k in the paper)\n");
		printf(" hie_num --> desired number of hierarchy levels\n");
		printf(" start_fr --> starting frame index\n");
		printf(" end_fr --> end frame index\n");
		printf("   input --> input path of ppm video frames\n");
		printf("  output --> output path of segmentation results\n");
		return 1;
	}

	// Read Parameters
	float c = (float)atof(argv[1]);
	float c_reg = (float)atof(argv[2]);
	int min_size = atoi(argv[3]);
	float sigma = (float)atof(argv[4]);
	int range = atoi(argv[5]);
	int hie_num = atoi(argv[6]);
	int start_frame_num = atoi(argv[7]);
	int end_frame_num = atoi(argv[8]);
	char* input_path = argv[9];
	char* output_path = argv[10];
	if (c <= 0 || c_reg < 0 || min_size < 0 || sigma < 0 || hie_num < 0) {
		fprintf(stderr, "Unable to use the input parameters.");
		return 1;
	}

	//subarna: optical flow
	double alpha = 0.012;
	double ratio = 0.75;
	int minWidth = 20;
	int nOuterFPIterations = 7;
	int nInnerFPIterations = 1;
	int nSORIterations = 30;

	// count files in the input directory
	/*int frame_num = 0;
	struct dirent* pDirent;
	DIR* pDir;
	pDir = opendir(input_path);
	if (pDir != NULL) {
		while ((pDirent = readdir(pDir)) != NULL) {
			int len = strlen(pDirent->d_name);
			if (len >= 4) {
				if (strcmp(".ppm", &(pDirent->d_name[len - 4])) == 0)
					frame_num++;
			}
		}
	}
	//http://msdn.microsoft.com/en-us/library/windows/desktop/aa365200%28v=vs.85%29.aspx
	if (frame_num == 0) {
		fprintf(stderr, "Unable to find video frames at %s", input_path);
		return 1;
	}
	printf("Total number of frames in fold is %d\n", frame_num);

	// check if the range is right
	if (range > frame_num)
		range = frame_num;
	if (range < 1)
		range = 1;
	*/
	
	// check if the range is right
	if (range > (end_frame_num - start_frame_num))
		range = (end_frame_num - start_frame_num);
	if (range < 1)
		range = 1;

# ifdef USE_OPTICAL_FLOW
	if (range < 2)
	{
		range = 2;
		printf("range value should at least be 2 if motion values are to be used\n");
		printf("making the range value 2");
		if ( (end_frame_num - start_frame_num) < 2 )
		{
			printf("\n Not enough frames ... exiting\n\n\n\n");
			exit(1);
		}
	}
# endif

	// make the output directory
	struct stat st;
	int status = 0;
	char savepath[1024];
  	sprintf(savepath, "%s",output_path);
	if (stat(savepath, &st) != 0) {
		/* Directory does not exist */
		if (mkdir(savepath/*, S_IRWXU*/) != 0) {
			status = -1;
		}
	}
	for (int i = 0; i <= hie_num; i++) {
  		sprintf(savepath, "%s/%02d",output_path,i);
		if (stat(savepath, &st) != 0) {
			/* Directory does not exist */
			if (_mkdir(savepath/*, S_IRWXU*/) != 0) { //subarna: _mkdir
				status = -1;
			}
		}
	}
	if (status == -1) {
		fprintf(stderr,"Unable to create the output directories at %s",output_path);
		return 1;
	}
 
	// Initialize Parameters
	int last_clip = (end_frame_num - start_frame_num + 1) % range;
	int num_clip = (end_frame_num - start_frame_num + 1) / range;
	char filepath[1024];
	universe** u = new universe*[num_clip + 1];

	image<rgb>** input_first = new image<rgb>*[range];
	image<rgb>** input_middle = new image<rgb>*[range + 1];
	image<rgb>** input_last = new image<rgb>*[last_clip + 1];

	//subarna
# ifdef LUV
	DImage** input_first_LUV = new DImage*[range];
	DImage** input_middle_LUV = new DImage*[range+1];
	DImage** input_last_LUV = new DImage*[last_clip+1];
# endif

	// Time Recorder
	time_t Start_t, End_t;
	int time_task;
	Start_t = time(NULL);

	int height, width;
	
	// clip 1
	//calculate pair-wise optical flow
	//initialize memory and first frame
	printf("processing subsequence -- 0\n");
	for (int j = 0; j < range; j++) {
		sprintf(filepath, "%s/%05d.ppm", input_path, j + 1+ start_frame_num);
		input_first[j] = loadPPM(filepath);
		
		printf("load --> %s\n", filepath);

		if (j == 0 )
		{
			height = input_first[0]->height();
			width = input_first[0]->width();
		}

# ifdef LUV
		input_first_LUV[j] = new DImage (width, height,3);
		int m = 0;
		//convert to LUV and then apply bilateral filter
		for (int s = 0; s < height*width; s++)
		{     
			double x1,y1,z1;
			double x2,y2,z2;
			ccRGBtoXYZ(input_first[j]->data[s].r, input_first[j]->data[s].g, input_first[j]->data[s].b, &x1, &y1, &z1);
			ccXYZtoCIE_Luv(x1, y1, z1, &x2, &y2, &z2);
			input_first_LUV[j]->pData[m] = x2, 
			input_first_LUV[j]->pData[m+1] = y2, 
			input_first_LUV[j]->pData[m+2] = z2;
			m = m+3;
		}
		// pass input_first_LUV
# endif

	}

#ifdef USE_OPTICAL_FLOW
	DImage** D_vx_motion_first = new DImage*[range];
	DImage** D_vx_motion_middle = new DImage*[range + 1];
	DImage** D_vx_motion_last = new DImage*[last_clip + 1];

	DImage** D_vy_motion_first = new DImage*[range];
	DImage** D_vy_motion_middle = new DImage*[range + 1];
	DImage** D_vy_motion_last = new DImage*[last_clip + 1];
# endif

# ifdef USE_OPTICAL_FLOW
	DImage** D_input_first = new DImage*[range];
	DImage** D_input_middle = new DImage*[range + 1];
	DImage** D_input_last = new DImage*[last_clip + 1];

	for (int i = 0; i < range; i++ )
	{
		D_input_first[i] = new DImage(width,height,3);
		D_vx_motion_first[i] = new DImage (width,height);
		D_vy_motion_first[i] = new DImage (width,height);
	}
	image<rgb>* motion_buffer = NULL;
	DImage* D_motion_buffer = new DImage(width,height,3);

	//initialize
	int m = 0;
	int m1 = 0;
	for(int k1= 0; k1 < width; k1++)
	{
		for (int k2 = 0; k2 < height; k2++)
		{
			D_input_first[0]->pData[m1] = input_first[0]->data[m].r;
			D_input_first[0]->pData[m1+1] = input_first[0]->data[m].g;
			D_input_first[0]->pData[m1+2] = input_first[0]->data[m].b;
			m++;
			m1=m1+3;
		}
	}
	D_input_first[0]->im2double();

	for (int j = 0; j < range-1; j++) {
		// initialization for consecutive frames
		m = 0;	
		m1 = 0;
		for(int k1= 0; k1 < width; k1++)
		{
			for (int k2 = 0; k2 < height; k2++)
			{
				D_input_first[j+1]->pData[m1] = input_first[j+1]->data[m].r;
				D_input_first[j+1]->pData[m1+1] = input_first[j+1]->data[m].g;
				D_input_first[j+1]->pData[m1+2] = input_first[j+1]->data[m].b;
				m++;
				m1=m1+3;
			}
		}
		D_input_first[j+1]->im2double();

		OpticalFlow::Coarse2FineTwoFrames(*D_input_first[j], *D_input_first[j+1], &D_vx_motion_first[j], &D_vy_motion_first[j], alpha,ratio,minWidth,nOuterFPIterations,nInnerFPIterations,nSORIterations);
		
# ifdef DUMP_FLOW
		//debug: to be deleted
		image<rgb>* test_out = new image<rgb>(width, height);
		int m = 0;	
		for(int k1= 0; k1 < width; k1++)
		{
			for (int k2 = 0; k2 < height; k2++)
			{
				//test_out->data[m].r = ((int)(fabs(D_vx_motion_first[j]->pData[m])*30)>>4)<<4;
				//test_out->data[m].g = ((int)(fabs(D_vy_motion_first[j]->pData[m])*30)>>4)<<4;
				//test_out->data[m].b = 0 ; //test_out->data[m].r;

				test_out->data[m].r = 50 + 30*((int)(fabs(D_vx_motion_first[j]->pData[m])));
				test_out->data[m].g = 50 + 30*((int)(fabs(D_vy_motion_first[j]->pData[m])));
				test_out->data[m].b = 0 ; //test_out->data[m].r;
				
				m++;
			}
		}
		sprintf(filepath,"%s/motion/%05d.ppm",output_path, j + 1+ start_frame_num);
		savePPM(test_out, filepath); //"out_test/test1.ppm"
		delete test_out;
# endif

	}
	delete input_first[0];
	sprintf(filepath, "%s/%05d.ppm", input_path, range +1 + start_frame_num);
	input_first[0] = loadPPM(filepath);
	m = 0;	
	m1 = 0;
	for(int k1= 0; k1 < width; k1++)
	{
		for (int k2 = 0; k2 < height; k2++)
		{
			D_motion_buffer->pData[m1] = input_first[0]->data[m].r;
			D_motion_buffer->pData[m1+1] = input_first[0]->data[m].g;
			D_motion_buffer->pData[m1+2] = input_first[0]->data[m].b;
			m++;
			m1=m1+3;
		}
	}
	// dummy place holder
	D_motion_buffer->im2double();
	OpticalFlow::Coarse2FineTwoFrames(*D_input_first[range-2], *D_motion_buffer, &D_vx_motion_first[range-1], &D_vy_motion_first[range-1], alpha,ratio,minWidth,nOuterFPIterations,nInnerFPIterations,nSORIterations);
	
# if 0
	//copy content from D_motion_first[j-1] to D_motion_first[range-1]
	D_vx_motion_first[range-1]->copyData(*D_vx_motion_first[range-2]);
	D_vy_motion_first[range-1]->copyData(*D_vy_motion_first[range-2]);
# endif
	///////////////////////////////////////
# endif

# ifdef USE_OPTICAL_FLOW
	// frame index starts from 0
	# ifndef LUV
		u[0] = segment_image(output_path, input_first, D_vx_motion_first, D_vy_motion_first, 0, range - 1, c, c_reg, min_size,
				sigma, hie_num, NULL,start_frame_num);
	# else
		u[0] = segment_image_LUV(output_path, input_first_LUV, D_vx_motion_first, D_vy_motion_first, 0, range - 1, c, c_reg, min_size,
				sigma, hie_num, NULL,start_frame_num);
	# endif
# else
	// frame index starts from 0
	# ifndef LUV
		u[0] = segment_image(output_path, input_first,0, range - 1, c, c_reg, min_size,
				sigma, hie_num, NULL,start_frame_num);
	# else
		u[0] = segment_image_LUV(output_path, input_first_LUV, 0, range - 1, c, c_reg, min_size,
				sigma, hie_num, NULL,start_frame_num);
	# endif
# endif

	for (int j = 0; j < range; j++) {
		delete input_first[j];
# ifdef LUV
		delete input_first_LUV[j];
# endif
	}

# ifdef USE_OPTICAL_FLOW  //subarna
	for (int j = 0; j < range; j++) {	

		delete D_vx_motion_first[j];
		delete D_vy_motion_first[j];

		delete D_input_first[j];
	}
# endif

	// clip 2 -- last
	int ii;
	for (ii = 1; ii < num_clip; ii++) 
	{
		printf("processing subsequence -- %d\n", ii);

		for (int j = 0; j < range + 1; j++) 
		{
			sprintf(filepath, "%s/%05d.ppm", input_path, ii * range + j + start_frame_num);
			input_middle[j] = loadPPM(filepath);
			
			printf("load --> %s\n", filepath);

# ifdef LUV
			input_middle_LUV[j] = new DImage (width, height,3);
			int m = 0;
			//convert to LUV and then apply bilateral filter
			for (int s = 0; s < height*width; s++)
			{     
				double x1,y1,z1;
				double x2,y2,z2;
				ccRGBtoXYZ(input_middle[j]->data[s].r, input_middle[j]->data[s].g, input_middle[j]->data[s].b, &x1, &y1, &z1);
				ccXYZtoCIE_Luv(x1, y1, z1, &x2, &y2, &z2);
				input_middle_LUV[j]->pData[m] = x2, 
				input_middle_LUV[j]->pData[m+1] = y2, 
				input_middle_LUV[j]->pData[m+2] = z2;
				m = m+3;
			}
			//pass input_middle_LUV
# endif
		}

# ifdef USE_OPTICAL_FLOW
		for (int i = 0; i < range+1; i++ )
		{
			D_input_middle[i] = new DImage(width,height,3);
			D_vx_motion_middle[i] = new DImage(width,height);
			D_vy_motion_middle[i] = new DImage(width,height);
		}
		//initialize 
		m = 0;
		m1 = 0;
		for(int k1= 0; k1 < width; k1++)
		{
			for (int k2 = 0; k2 < height; k2++)
			{
				D_input_middle[0]->pData[m1] = input_middle[0]->data[m].r;
				D_input_middle[0]->pData[m1+1] = input_middle[0]->data[m].g;
				D_input_middle[0]->pData[m1+2] = input_middle[0]->data[m].b;
				m++;
				m1=m1+3;
			}
		}
		D_input_middle[0]->im2double();
		//calculate pair-wise optical flow 
		for (int j = 0; j < range; j++) {
			// initialization for consecutive frames
			m = 0;	
			m1 = 0;
			for(int k1= 0; k1 < width; k1++)
			{
				for (int k2 = 0; k2 < height; k2++)
				{
					D_input_middle[j+1]->pData[m1] = input_middle[j+1]->data[m].r;
					D_input_middle[j+1]->pData[m1+1] = input_middle[j+1]->data[m].g;
					D_input_middle[j+1]->pData[m1+2] = input_middle[j+1]->data[m].b;
					m++;
					m1 =m1+3;
				}
			}
			D_input_middle[j+1]->im2double();
			OpticalFlow::Coarse2FineTwoFrames(*D_input_middle[j], *D_input_middle[j+1], &D_vx_motion_middle[j], &D_vy_motion_middle[j], alpha,ratio,minWidth,nOuterFPIterations,nInnerFPIterations,nSORIterations);
		
# ifdef DUMP_FLOW
			//debug: to be deleted
			image<rgb>* test_out = new image<rgb>(width, height);
			int m = 0;	
			for(int k1= 0; k1 < width; k1++)
			{
				for (int k2 = 0; k2 < height; k2++)
				{
					//test_out->data[m].r = ((int)(fabs(D_vx_motion_first[j]->pData[m])*30)>>4)<<4;
					//test_out->data[m].g = ((int)(fabs(D_vy_motion_first[j]->pData[m])*30)>>4)<<4;
					//test_out->data[m].b = 0 ; //test_out->data[m].r;

					test_out->data[m].r = 50 + 40*((int)(fabs(D_vx_motion_middle[j]->pData[m])));
					test_out->data[m].g = 50 + 40*((int)(fabs(D_vx_motion_middle[j]->pData[m])));
					test_out->data[m].b = 0 ; //test_out->data[m].r;
				
					m++;
				}
			}
			sprintf(filepath,"%s/motion/%05d.ppm",output_path, i * range + j + start_frame_num);
			savePPM(test_out, filepath); //"out_test/test1.ppm"
			delete test_out;
# endif

		}
				
		// subarna: fix crash for specific frame number case
		if ( (ii == num_clip - 1 ) && (last_clip == 0) )
		{
			// for the last frame motion feature -- copy feature value from last frame, but with opposite sign
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					D_vx_motion_middle[range]->pData[i*width + j] = -D_vx_motion_middle[range-1]->pData[i*width + j];
					D_vy_motion_middle[range]->pData[i*width + j] = -D_vy_motion_middle[range-1]->pData[i*width + j];
				}
			}
		}
		else
		{
			delete input_middle[0];
			sprintf(filepath, "%s/%05d.ppm", input_path, (ii+1) * range +1 + start_frame_num);
			input_middle[0] = loadPPM(filepath);		

			m = 0;	
			m1 = 0;
			for(int k1= 0; k1 < width; k1++)
			{
				for (int k2 = 0; k2 < height; k2++)
				{
					D_motion_buffer->pData[m1] = input_middle[0]->data[m].r;
					D_motion_buffer->pData[m1+1] = input_middle[0]->data[m].g;
					D_motion_buffer->pData[m1+2] = input_middle[0]->data[m].b;
					m++;
					m1=m1+3;
				}
			}
			
			// dummy place holder
			D_motion_buffer->im2double();
			OpticalFlow::Coarse2FineTwoFrames(*D_input_middle[range], *D_motion_buffer, &D_vx_motion_middle[range], &D_vy_motion_middle[range], alpha,ratio,minWidth,nOuterFPIterations,nInnerFPIterations,nSORIterations);
			/////////////////////////////////////
		}
# endif


# ifdef USE_OPTICAL_FLOW
	# ifndef LUV
		u[ii] = segment_image(output_path, input_middle, D_vx_motion_middle, D_vy_motion_middle, ii * range - 1,
				ii * range + range - 1, c, c_reg, min_size, sigma, hie_num,
				u[ii - 1], start_frame_num);
	# else
			u[ii] = segment_image_LUV(output_path, input_middle_LUV, D_vx_motion_middle, D_vy_motion_middle, ii * range - 1,
					ii * range + range - 1, c, c_reg, min_size, sigma, hie_num,
					u[ii - 1],start_frame_num);
	# endif
# else
	# ifndef LUV
		u[ii] = segment_image(output_path, input_middle, ii * range - 1,
				ii * range + range - 1, c, c_reg, min_size, sigma, hie_num,
				u[ii - 1], start_frame_num);
	# else
			u[ii] = segment_image_LUV(output_path, input_middle_LUV, ii * range - 1,
					ii* range + range - 1, c, c_reg, min_size, sigma, hie_num,
					u[ii - 1],start_frame_num);
	# endif
# endif

		if ( u[ii-1] ) delete u[ii - 1];

		////////////////////
		for (int j = 0; j < range + 1; j++) 
		{
			delete input_middle[j];			
# ifdef LUV
			delete input_middle_LUV[j];
# endif
		}

		# ifdef USE_OPTICAL_FLOW
		for (int j = 0; j < range + 1; j++) 
		{

			delete D_vx_motion_middle[j];
			delete D_vy_motion_middle[j];
			delete D_input_middle[j];
		}
		# endif
	}

	// clip last
	if (last_clip > 0) {
		printf("processing subsequence -- %d\n", num_clip);

		for (int j = 0; j < last_clip + 1; j++) 
		{
			sprintf(filepath, "%s/%05d.ppm", input_path, num_clip * range + j + start_frame_num);

			input_last[j] = loadPPM(filepath);

			printf("load --> %s\n", filepath);

# ifdef LUV
			input_last_LUV[j] = new DImage (width, height,3);
			int m=0;
			for (int s = 0; s < width*height; s++)
			{     
				double x1,y1,z1;
				double x2,y2,z2;
				ccRGBtoXYZ(input_last[j]->data[s].r, input_last[j]->data[s].g, input_last[j]->data[s].b, &x1, &y1, &z1);
				ccXYZtoCIE_Luv(x1, y1, z1, &x2, &y2, &z2);
				input_last_LUV[j]->pData[m] = x2, 
				input_last_LUV[j]->pData[m+1] = y2, 
				input_last_LUV[j]->pData[m+2] = z2;
				m = m+3;
			}
# endif
		}

# ifdef USE_OPTICAL_FLOW
		//subarna
		for (int i = 0; i < last_clip+1; i++ )
		{
			D_input_last[i] = new DImage(width,height,3);
			D_vx_motion_last[i] = new DImage(width,height);
			D_vy_motion_last[i] = new DImage(width,height);
		}
		//subarna
		//initialize
		m1 = 0;
		m = 0;
		for(int k1= 0; k1 < width; k1++)
		{
			for (int k2 = 0; k2 < height; k2++)
			{
				D_input_last[0]->pData[m1] = input_last[0]->data[m].r;
				D_input_last[0]->pData[m1+1] = input_last[0]->data[m].g;
				D_input_last[0]->pData[m1+2] = input_last[0]->data[m].b;//0
				m++;
				m1=m1+3;
			}
		}
		D_input_last[0]->im2double();
		//calculate pair-wise optical flow 
		for (int j = 0; j < last_clip; j++) {
			// initialization for consecutive frames
			m = 0;
			m1 = 0;
			for(int k1= 0; k1 < width; k1++)
			{
				for (int k2 = 0; k2 < height; k2++)
				{
					D_input_last[j+1]->pData[m1] = input_last[j+1]->data[m].r;
					D_input_last[j+1]->pData[m1+1] = input_last[j+1]->data[m].g;
					D_input_last[j+1]->pData[m1+2] = input_last[j+1]->data[m].b;
					m++;
					m1=m1+3;
				}
			}
			D_input_last[j+1]->im2double();
			OpticalFlow::Coarse2FineTwoFrames(*D_input_last[j], *D_input_last[j+1], &D_vx_motion_last[j], &D_vy_motion_last[j], alpha,ratio,minWidth,nOuterFPIterations,nInnerFPIterations,nSORIterations);

# ifdef DUMP_FLOW
			//debug: to be deleted
			image<rgb>* test_out = new image<rgb>(width, height);
			int m = 0;	
			for(int k1= 0; k1 < width; k1++)
			{
				for (int k2 = 0; k2 < height; k2++)
				{
					//test_out->data[m].r = ((int)(fabs(D_vx_motion_first[j]->pData[m])*30)>>4)<<4;
					//test_out->data[m].g = ((int)(fabs(D_vy_motion_first[j]->pData[m])*30)>>4)<<4;
					//test_out->data[m].b = 0 ; //test_out->data[m].r;

					test_out->data[m].r = 50 + 30*((int)(fabs(D_vx_motion_last[j]->pData[m])));
					test_out->data[m].g = 50 + 30*((int)(fabs(D_vx_motion_last[j]->pData[m])));
					test_out->data[m].b = 0 ; //test_out->data[m].r;
				
					m++;
				}
			}
			sprintf(filepath,"%s/motion/%05d.ppm",output_path, num_clip * range + j + start_frame_num);
			savePPM(test_out, filepath); //"out_test/test1.ppm"
			delete test_out;
# endif
		}

		// for the last frame motion feature -- copy feature value from last frame, but with opposite sign
		for (int i = 0; i < height; i++)
		{
			for (int j = 0; j < width; j++)
			{
				D_vx_motion_last[last_clip]->pData[i*width + j] = -D_vx_motion_last[last_clip-1]->pData[i*width + j];
				D_vy_motion_last[last_clip]->pData[i*width + j] = -D_vy_motion_last[last_clip-1]->pData[i*width + j];
			}
		}
		//////////////////////////////////////
# endif

# ifdef USE_OPTICAL_FLOW
	# ifndef LUV
			u[num_clip] = segment_image(output_path, input_last, D_vx_motion_last,D_vy_motion_last, num_clip * range - 1,
					num_clip * range + last_clip - 1, c, c_reg, min_size, sigma,
					hie_num, u[num_clip - 1],start_frame_num);
	# else
			u[num_clip] = segment_image_LUV(output_path, input_last_LUV, D_vx_motion_last,D_vy_motion_last, num_clip * range - 1,
					num_clip * range + last_clip - 1, c, c_reg, min_size, sigma,hie_num, u[num_clip - 1],start_frame_num);
	# endif
# else
	# ifndef LUV
			u[num_clip] = segment_image(output_path, input_last,num_clip * range - 1,
					num_clip * range + last_clip - 1, c, c_reg, min_size, sigma,
					hie_num, u[num_clip - 1],start_frame_num);
	# else
			u[num_clip] = segment_image_LUV(output_path, input_last_LUV, num_clip * range - 1,
					num_clip * range + last_clip - 1, c, c_reg, min_size, sigma,hie_num, u[num_clip - 1],start_frame_num);
	# endif
# endif


		if (u[num_clip - 1]) delete u[num_clip - 1];
		delete u[num_clip];

		for (int j = 0; j < last_clip + 1; j++) 
		{
			delete input_last[j];			
# ifdef LUV
			delete input_last_LUV[j];
# endif
		}

		//subarna
# ifdef USE_OPTICAL_FLOW
		for (int j = 0; j < last_clip + 1; j++) {

			delete D_vx_motion_last[j];
			delete D_vy_motion_last[j];
			delete D_input_last[j];
		}
		delete(D_motion_buffer);
# endif
	}

	//////////////////////////////////////
# ifdef LUV
	delete input_first_LUV;
	delete input_middle_LUV;
	delete input_last_LUV;
# endif

# ifdef USE_OPTICAL_FLOW
	delete D_vx_motion_first;
	delete D_vy_motion_first;
	delete D_vx_motion_middle;
	delete D_vy_motion_middle;
	delete D_vx_motion_last;
	delete D_vy_motion_last;
# endif
	/////////////////////////////////////

	delete[] u;

	// Time Recorder
	End_t = time(NULL);
	time_task = difftime(End_t, Start_t);
	std::ofstream myfile;
	char timefile[1024];
	sprintf(timefile, "%s/%s", output_path, "time.txt");
	myfile.open(timefile);
	myfile << time_task << endl;
	myfile.close();

	printf("Congratulations! It's done!\n");
	printf("Time_total = %d seconds\n", time_task);
	return 0;
}
Beispiel #27
0
const bool OTPaths::ConfirmCreateFolder(const OTString & strExactPath, bool & out_Exists, bool & out_IsNew)
{
	const bool bExists = (strExactPath.Exists() && !strExactPath.Compare(""));
	OT_ASSERT_MSG(bExists,"OTPaths::ConfirmCreateFolder: Assert failed: no strFolderName\n");

	std::string l_strExactPath(strExactPath.Get());

	if ('/' != *l_strExactPath.rbegin()) return false; // not a directory.

	// Confirm If Directory Exists Already
	out_Exists = PathExists(strExactPath);

	if (out_Exists)
	{
		out_IsNew = false;
		return true;  // Already Have Folder, lets return true!
	}
	else 
	{
		// It dosn't exist: lets create it.

#ifdef _WIN32
		bool bCreateDirSuccess = (_mkdir(strExactPath.Get()) == 0);
#else
		bool bCreateDirSuccess = (mkdir(strExactPath.Get(), 0700) == 0);
#endif

		if (!bCreateDirSuccess) 
		{
			OTLog::vError("OTPaths::%s: Unable To Confirm "
				"Created Directory %s.\n", __FUNCTION__, strExactPath.Get());
			out_IsNew = false;
			out_Exists = false;
			return false;
		}

		// At this point if the folder still doesn't exist, nothing we can do. We
		// already tried to create the folder, and SUCCEEDED, and then STILL failed 
		// to find it (if this is still false.)

		else 
		{
			bool bCheckDirExist = PathExists(strExactPath);

			if (!bCheckDirExist) 
			{
				OTLog::vError("OTPaths::%s: "
					"Unable To Confirm Created Directory %s.\n", 
					__FUNCTION__, strExactPath.Get());
				out_IsNew = false;
				out_Exists = false;
				return false;
			}
			else
			{
				out_IsNew = true;
				out_Exists = false;
				return true;  // We have created and checked the Folder
			}
		}
		return false; // should never happen.
	}
}
Beispiel #28
0
int main() {
//	srand(time(0));
//	generateInst(CASE);

	for(CASE = 1; CASE<=10; CASE++) {
		_mkdir("GAgrid");
		strcpy(strdir,"GAgrid//inst");
		itoa(CASE,ch,10);
		strcat(strdir,ch);
		_mkdir(strdir);
		strcat(strdir,"//");
	readInst(CASE);

	int i,j;
	int gen;
	clock_t start;			//////////////////
	avg_result_time = 0;	//////////////////
	for(trialNum = 1; trialNum <= TRIALNUM; trialNum++) {
		strcpy(str,strdir);
		strcat(str,"result.txt");
		ftotal = fopen(str,"a");

		strcpy(str,strdir);
		itoa(trialNum,ch,10);
		strcat(str,"resultMnum");
		strcat(str,ch);
		strcat(str,".txt");
		fresultgMnum = fopen(str,"w");

		strcpy(str,strdir);
		strcat(str,"runtime");
		strcat(str,ch);
		strcat(str,".txt");
		fruntime = fopen(str,"w");

		start = clock();	//////////////////
		gen = 0;
		initialize(CASE);
		evaluate(CASE);
		keep_the_best();
		while(gen < MAXGENS) {
			select();			//using roulette wheel selection
			crossover();
			mutate();
			evaluate(CASE);	
			elitist();						
			gen++;
		//	printf("%d\t%g\t%g\n",gen,pop[POPSIZE].fitness,pop[POPSIZE].cost);
			fprintf(fruntime,"%d\t%g\t%g\n",gen,pop[POPSIZE].fitness,pop[POPSIZE].cost);
		}
		avg_result_time += clock() - start; //////////////////
		printf("%d\t%g\t%g\n",trialNum,pop[POPSIZE].fitness,pop[POPSIZE].cost);
		fprintf(ftotal,"%d\t%g\t%g\t%g\n",trialNum,pop[POPSIZE].fitness,pop[POPSIZE].cost,(double)avg_result_time/trialNum);//////////////////
		for(i=0;i<24;i++) {
			for(j=0;j<MTYPE;j++) {
				fprintf(fresultgMnum,"%d\t",pop[POPSIZE].gMnum[i][j]);
			}
			fprintf(fresultgMnum,"\n");
		}
	//	printf("\n");
		fprintf(fresultgMnum,"\n");
		fclose(fresultgMnum);
		fclose(ftotal);
		fclose(fruntime);
	}
	}

	return 0;
}
/*!
* For a given path, this method creates the specified directory path
* including all required sub-directories.
*
* \param path path to create
*
* \return file status
*/
int CUtil::MkPath(const string &path)
{
    size_t i = 1;
    string tpath;
#ifdef UNIX
    struct stat st;
    if (stat(path.c_str(), &st) != 0)
    {
        while (i < path.size())
        {
            if (path[i] == '/')
            {
                tpath = path.substr(0, i);
                if (stat(tpath.c_str(), &st) != 0)
                {
                    if (mkdir(tpath.c_str(), 0777) != 0)
                        return 0;
                }
            }
            i++;
        }
        if (mkdir(path.c_str(), 0777) != 0)
            return 0;
    }
    string tempfile = path + "/___temp.dat";
#else
    if (_access(path.c_str(), 0) != 0)
    {
        while (i < path.size())
        {
            if ((path[i] == '\\' || path[i] == '/') && path[i-1] != ':')
            {
                tpath = path.substr(0, i);
                if (_access(tpath.c_str(), 0) != 0)
                {
                    if (_mkdir(tpath.c_str()) != 0)
                        return 0;
                }
            }
            i++;
        }
        if (_mkdir(path.c_str()) != 0)
            return 0;
    }
    string tempfile = path + "\\___temp.dat";
#endif

    // attempt to write a temporary file to the directory
    ofstream outfile;
    outfile.open(tempfile.c_str(), ofstream::out);
    outfile.close();
    if (outfile.fail())
    {
        // file could not be opened
        return 0;
    }
    else
    {
        // delete the temporary file
        remove(tempfile.c_str());
    }
    return 1;
}
Beispiel #30
0
void save_itemTofile(char* filename,char* filetype)
{
#ifndef __HIDE_PSP_FUNC_
	char path[256];
	FILE* fp = NULL;
	FILE* out = NULL;
	packItem* temp = NULL;
	unsigned char* type = NULL;
	unsigned char* buf = NULL;
	fp = fopen(filename,"rb");
	if(fp==NULL) return;
	if(packInit(filename)==-1) {
		printf("------------------------------------------------------------\n");
		printf("解包失败,这不是一个符合规格的打包文件...\n\n");
		return;
	}
	temp = fileItem;
	printf("------------------------------------------------------------\n");
	while(temp!=NULL)
	{
		if( !strcmp(filetype,"*") )
			type=temp->date.name;
		else
			type = (unsigned char*)filetype;
		if( strstr((char*)type,"jpg") || strstr((char*)type,"JPG") || \
			strstr((char*)type,"bmp") || strstr((char*)type,"BMP") || \
			strstr((char*)type,"gif") || strstr((char*)type,"GIF") || \
			strstr((char*)type,"png") || strstr((char*)type,"PNG") || \
			strstr((char*)type,"tag") || strstr((char*)type,"TAG") ) {
			if( strstr((char*)temp->date.name,(char*)type) ) {
				strcpy(path,"images");
				_mkdir(path);
				buf = (unsigned char*) safe_malloc (temp->date.size);
				fseek(fp,temp->date.offset,SEEK_SET);
				fread(buf,temp->date.size,1,fp);
				strcat(path,"/");
				strcat(path,(char*)temp->date.name);
				out = fopen(path,"wb");
				fwrite(buf,temp->date.size,1,out);
				safe_free(buf);
				fclose(out);
				printf("解包文件 <%s> 成功...\n",temp->date.name);
			}
			if(type != temp->date.name)
				if(!strcmp((char*)temp->date.name,(char*)type)) break;
		}
		if( strstr((char*)type,"mp3") || strstr((char*)type,"MP3") || \
			strstr((char*)type,"wav") || strstr((char*)type,"WAV") || \
			strstr((char*)type,"ogg") || strstr((char*)type,"OGG") ) {
			if( strstr((char*)temp->date.name,(char*)type) ) {
				strcpy(path,"sounds");
				_mkdir(path);
				buf = (unsigned char*) safe_malloc (temp->date.size);
				fseek(fp,temp->date.offset,SEEK_SET);
				fread(buf,temp->date.size,1,fp);
				strcat(path,"/");
				strcat(path,(char*)temp->date.name);
				out = fopen(path,"wb");
				fwrite(buf,temp->date.size,1,out);
				safe_free(buf);
				fclose(out);
				printf("解包文件 <%s> 成功...\n",temp->date.name);
			}
			if(type != temp->date.name)
				if(!strcmp((char*)temp->date.name,(char*)type)) break;
		}
		if( strstr((char*)type,"pmp") || strstr((char*)type,"PMP") ) {
			if( strstr((char*)temp->date.name,(char*)type) ) {
				strcpy(path,"videos");
				_mkdir(path);
				buf = (unsigned char*) safe_malloc (temp->date.size);
				fseek(fp,temp->date.offset,SEEK_SET);
				fread(buf,temp->date.size,1,fp);
				strcat(path,"/");
				strcat(path,(char*)temp->date.name);
				out = fopen(path,"wb");
				fwrite(buf,temp->date.size,1,out);
				safe_free(buf);
				fclose(out);
				printf("解包文件 <%s> 成功...\n",temp->date.name);
			}
			if(type != temp->date.name)
				if(!strcmp((char*)temp->date.name,(char*)type)) break;
		}
		temp = temp->next;
	}
	printf("------------------------------------------------------------\n");
	printf("解包完毕!\n\n");
	packFini();
#endif
}