Ejemplo n.º 1
0
	virtual void OnTimeout()
	{
		/* This test protects against using widgets 11 and 12 which are only available
		 * in those saveload modes. */
		if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP)) return;

		if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked
			if (!FiosDelete(this->filename_editbox.text.buf)) {
				ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR);
			} else {
				this->InvalidateData();
				/* Reset file name to current date on successful delete */
				if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
			}
		} else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
			if (_saveload_mode  == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
				_switch_mode = SM_SAVE_GAME;
				FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, sizeof(_file_to_saveload.name));
			} else {
				_switch_mode = SM_SAVE_HEIGHTMAP;
				FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, sizeof(_file_to_saveload.name));
			}

			/* In the editor set up the vehicle engines correctly (date might have changed) */
			if (_game_mode == GM_EDITOR) StartupEngines();
		}
	}
Ejemplo n.º 2
0
// Create a filename, based on DEFCERT entry
char *GenerateFileName(unsigned int version_num, const DEFCERT_st *entry, BOOL with_pub_key, const DEFCERT_keyid_item *item)
{
	if(entry->dercert_data == NULL)
		return NULL;
	
	return GenerateFileName(version_num, entry->dercert_data, entry->dercert_len, with_pub_key, item);
}
Ejemplo n.º 3
0
	virtual void OnTimeout()
	{
		/* Widgets WID_SL_DELETE_SELECTION and WID_SL_SAVE_GAME only exist when saving to a file. */
		if (this->fop != SLO_SAVE) return;

		if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked
			if (!FiosDelete(this->filename_editbox.text.buf)) {
				ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR);
			} else {
				this->InvalidateData(SLIWD_RESCAN_FILES);
				/* Reset file name to current date on successful delete */
				if (this->abstract_filetype == FT_SAVEGAME) GenerateFileName();
			}
		} else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
			if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
				FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
				if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) {
					ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveGameConfirmationCallback);
				} else {
					_switch_mode = SM_SAVE_GAME;
				}
			} else {
				FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
				if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) {
					ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
				} else {
					_switch_mode = SM_SAVE_HEIGHTMAP;
				}
			}

			/* In the editor set up the vehicle engines correctly (date might have changed) */
			if (_game_mode == GM_EDITOR) StartupEngines();
		}
	}
Ejemplo n.º 4
0
   void
   Message::Initialize(bool generateFileName)
   {
      m_iMessageAccountID = 0;
      m_iMessageState = Created;
      m_iMessageFolderID = 0;
      m_iMessageSize = 0;
      m_iNoOfRetries = 0;
      _uid = 0;

      if (generateFileName)
      {
         m_sFilename = GenerateFileName();
      }

      // Message flags.
      m_iFlags = 0;
   }
Ejemplo n.º 5
0
   void
   Message::Initialize(bool generateFileName)
   {
      message_account_id_ = 0;
      message_state_ = Created;
      message_folder_id_ = 0;
      message_size_ = 0;
      no_of_retries_ = 0;
      uid_ = 0;

      if (generateFileName)
      {
         filename_ = GenerateFileName();
      }

      // Message flags.
      flags_ = 0;
   }
Ejemplo n.º 6
0
void USBDataFilev2012::WriteToFile(const char* szFolder)
{
	string buf;
	unsigned short blocks = htons(nDataBlockNumber);
	buf.append((const char*) &blocks, sizeof(blocks));
	map<int, DataSet>::iterator it;
	for (it = Datas.begin(); it != Datas.end(); it++)
	{
		if (it->second.empty())
			continue;
		DataSet::iterator data_set;
		USBDataBlock block =
		{ 0 };
		block.cDataCode = it->second.front()->GetDataCode();
		string strName = DataBlockName[block.cDataCode];
		VTDRRecord::utf8togb2312(strName.c_str(), strName.size(),
				(char*) block.cDataName, sizeof(block.cDataName));

		string strBlock;
		for (data_set = it->second.begin(); data_set != it->second.end();
				data_set++)
		{
			(*data_set)->Write(strBlock);
		}
		block.nDataLength = htonl(strBlock.size());
		buf.append((const char*) &block, sizeof(block));
		buf.append(strBlock);
	}
	buf.append(1, checkSum(buf));

	GenerateFileName();
	FILE* fp = fopen(strFileName.c_str(), "wb");
	if (fp)
	{
		int n = fwrite((void*) buf.data(), 1, buf.size(), fp);
		fclose(fp);
		if (n != 1)
		{
			throw USBDataFileException("write fail");
		}
		return;
	}
	throw USBDataFileException("open file for write fail");
}
Ejemplo n.º 7
0
/* Create a filename and open the file, according to the specified cert, key and keyid in a given path*/ 
BIO *GenerateFile(const char *version, unsigned int version_num, const char *path, 
		const byte *dercert_data, size_t dercert_len, 
		BOOL with_pub_key, const DEFCERT_keyid_item *item)
{
	if(dercert_data == NULL)
		return NULL;
	BIO *ret = NULL;
	char *filename = NULL;

	do
	{
		filename = GenerateFileName(version_num, dercert_data, dercert_len, with_pub_key, item);
		if(filename == NULL)
			break;
		ret = GenerateFile(version, path, filename);
	}while(0);

	delete [] filename;

	return ret;
}
Ejemplo n.º 8
0
static void SavePNG(uint8_t* buffer, int width, int height)
{
    wchar_t* fileName = xmalloc(32768 * sizeof(wchar_t));

    GenerateFileName(fileName, 32768);

    if (ShowSaveDialog(fileName, 32768))
    {
        FILE* file = OpenFileWrite(fileName);

        if (!file)
            Fatal(L"Couldn't write file.");

        if (!WritePNG(file, buffer, width, height))
            Fatal(L"Couldn't write PNG.");

        fclose(file);
    }

    free(fileName);
}
Ejemplo n.º 9
0
VOID
DumpDriver(__in PUNICODE_STRING FullImageName)
{
    NTSTATUS status;
    ULONG FileSize = 0;
    OBJECT_ATTRIBUTES ObjAttr = {0};
    IO_STATUS_BLOCK IoStatus = {0};
    FILE_STANDARD_INFORMATION FileInfo = {0};
    HANDLE SrcFileHandle, DstFileHandle;
    UNICODE_STRING DumpName = {0};
    PVOID Buffer;

    ObjAttr.Length = sizeof(OBJECT_ATTRIBUTES);
    ObjAttr.Attributes = OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE;
    ObjAttr.ObjectName = FullImageName;


    status = NtOpenFile(&SrcFileHandle,
                        FILE_READ_DATA,
                        &ObjAttr,
                        &IoStatus,
                        FILE_SHARE_VALID_FLAGS,
                        FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);
    if(!NT_SUCCESS(status))
    {
        DbgPrint("[!!] Cannot NtOpenFile %wZ, NtStatus: %08x\n", FullImageName, status);
        return;
    }

    status = NtQueryInformationFile(SrcFileHandle,
                                    &IoStatus,
                                    &FileInfo,
                                    sizeof(FILE_STANDARD_INFORMATION),
                                    FileStandardInformation);
    if(!NT_SUCCESS(status))
    {
        DbgPrint("[!!] Cannot NtQueryInformationFile %wZ, NtStatus: %08x\n", FullImageName, status);
        NtClose(SrcFileHandle);
        return;
    }

    FileSize = FileInfo.EndOfFile.LowPart ? FileInfo.EndOfFile.LowPart : FileInfo.AllocationSize.LowPart;
    if(!FileSize)
    {
        DbgPrint("[!!] Got zero file size for %wZ, NtStatus: %08x\n", FullImageName, status);
        NtClose(SrcFileHandle);
        return;
    }



    memset(&ObjAttr, 0x0, sizeof(OBJECT_ATTRIBUTES));
    ObjAttr.Length = sizeof(OBJECT_ATTRIBUTES);
    ObjAttr.Attributes = OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE;
    RtlInitUnicodeString(&DumpName, GenerateFileName(FullImageName));
    ObjAttr.ObjectName = &DumpName;

    DbgPrint("Dumping %wZ\n", &DumpName);
    status = NtCreateFile(&DstFileHandle,
                          GENERIC_WRITE,
                          &ObjAttr,
                          &IoStatus,
                          NULL,
                          FILE_ATTRIBUTE_NORMAL,
                          0,
                          FILE_SUPERSEDE,
                          FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE,
                          NULL,
                          0);

    if(!NT_SUCCESS(status))
    {
        DbgPrint("[!!] Cannot NtCreateFile %wZ, NtStatus: %08x\n", ObjAttr.ObjectName, status);
        NtClose(SrcFileHandle);
        ExFreePoolWithTag(DumpName.Buffer, 'w00t');

        return;
    }

    Buffer = ExAllocatePoolWithTag(NonPagedPool, FileSize, 'w00t');
    RtlZeroMemory(Buffer, FileSize);
    status = NtReadFile(SrcFileHandle,
                        NULL,
                        NULL,
                        NULL,
                        &IoStatus,
                        Buffer,
                        FileSize,
                        0,
                        0);

    if(!NT_SUCCESS(status))
    {
        DbgPrint("[!!] Cannot NtReadFile %wZ, NtStatus: %08x\n", ObjAttr.ObjectName, status);
        ExFreePoolWithTag(Buffer, 'w00t');
        ExFreePoolWithTag(DumpName.Buffer, 'w00t');
        NtClose(SrcFileHandle);
        NtClose(DstFileHandle);
        return;
    }

    status = NtWriteFile(DstFileHandle,
                         NULL,
                         NULL,
                         NULL,
                         &IoStatus,
                         Buffer,
                         FileSize,
                         0,
                         0);

    if(!NT_SUCCESS(status))
        DbgPrint("[!!] Cannot NtWriteFile %wZ, NtStatus: %08x\n", ObjAttr.ObjectName, status);


    ExFreePoolWithTag(Buffer, 'w00t');
    ExFreePoolWithTag(DumpName.Buffer, 'w00t');
    NtClose(SrcFileHandle);
    NtClose(DstFileHandle);
}