Esempio n. 1
0
FileInfo *ShareMng::SetFileInfo(char *fname)
{
	WIN32_FIND_DATA_U8	fdat;

	if (!GetFileInfomationU8(fname, &fdat))	return	FALSE;

	FileInfo	*info = new FileInfo;

	UINT	attr = (fdat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? IPMSG_FILE_DIR : IPMSG_FILE_REGULAR;
	attr |= (fdat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? IPMSG_FILE_RONLYOPT : 0;
	attr |= (fdat.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? IPMSG_FILE_SYSTEMOPT : 0;
	info->SetAttr(attr);
	info->SetFname(fname);
	if (GET_MODE(info->Attr()) == IPMSG_FILE_DIR)
	{
		info->SetSize(0);
		strncpyz(cfg->lastOpenDir, fname, MAX_PATH_U8);
	}
	else {
		info->SetSize((_int64)fdat.nFileSizeHigh << 32 | fdat.nFileSizeLow);
		PathToDir(fname, cfg->lastOpenDir);
	}
	info->SetMtime(FileTime2UnixTime(&fdat.ftLastWriteTime));
	info->SetCrtime(FileTime2UnixTime(&fdat.ftCreationTime));
	info->SetAtime(FileTime2UnixTime(&fdat.ftLastAccessTime));

	return	info;
}
Esempio n. 2
0
void	OpenSource(CString &dir)

{
	CWedDoc *pDoc;

	//P2N("OpenSource %p '%s' \r\n", dir, dir);

	CFileDialogST cdf(TRUE);
	CString droot, dresult, dfile, fname;
	char *buff = (char*)malloc(MAXFILENAMES + 1);

	if(!buff)
		{
		AfxMessageBox("Cannot get memory for OpenFile");
		return;
		}
	*buff = '\0';

	//if(dir == "")
	//	cdf.m_ofn.lpstrInitialDir = droot;
	//else
	
	cdf.m_ofn.lpstrInitialDir = dir;

	cdf.m_ofn.lpstrFilter = Ffilter;
	cdf.m_ofn.lpstrFile = (char *)buff;
	cdf.m_ofn.nMaxFile = MAXFILENAMES;
	cdf.m_ofn.nFilterIndex = 1;
	cdf.m_ofn.Flags |= OFN_ALLOWMULTISELECT;

	if(cdf.DoModal() == IDOK)
		{
		POSITION pos = cdf.GetStartPosition();
		while(TRUE)
			{
			if (!pos)
				break;
			fname = cdf.GetNextPathName(pos);
			pDoc = (CWedDoc*)
					AfxGetApp()->OpenDocumentFile(fname);
			if(!pDoc)
				break;

			if(YieldToWinEx())
				break;
			}
		dir = fname;
		PathToDir(dir);
		}
	free(buff);
}
Esempio n. 3
0
BOOL TShareDlg::AddList(int idx)
{
	char	buf[MAX_BUF_EX];

	ForcePathToFname(shareInfo->fileInfo[idx]->Fname(), buf);
	shareListView.InsertItem(idx, buf);

	if (GET_MODE(shareInfo->fileInfo[idx]->Attr()) == IPMSG_FILE_DIR)
		strcpy(buf, "(DIR)");
	else
		MakeSizeString(buf, shareInfo->fileInfo[idx]->Size(), MSS_SPACE);
	shareListView.SetSubItem(idx, 1, buf);

	PathToDir(shareInfo->fileInfo[idx]->Fname(), buf);
	shareListView.SetSubItem(idx, 2, buf);

	return	TRUE;
}
Esempio n. 4
0
int TSaveCommonDlg::Exec(void)
{
	modalFlg = TRUE;

	char	fname[MAX_BUF], last_dir[MAX_BUF], buf[MAX_BUF], *ext;

	// 最終保存ディレクトリが無くなっている場合、少しさかのぼる
	for (int i=0; i < 5; i++) {
		if (*cfg->lastSaveDir && GetFileAttributesU8(cfg->lastSaveDir) == 0xffffffff)
			if (!PathToDir(cfg->lastSaveDir, cfg->lastSaveDir))
				break;
	}

	strcpy(last_dir, *cfg->lastSaveDir ? cfg->lastSaveDir : ".");

	while (1) {
		FileInfo	*fileInfo = shareInfo->fileInfo[offset];

		MakePath(fname, last_dir, fileInfo->Fname());

	// ファイルダイアログ
		TApp::GetApp()->AddWin(this);
		BOOL	ret = OpenFileDlg(parentWin, OpenFileDlg::NODEREF_SAVE, (LPOFNHOOKPROC)TApp::WinProc).Exec(fname, GetLoadStrU8(IDS_SAVEFILE), GetLoadStrAsFilterU8(IDS_OPENFILEALLFLTR), last_dir);
		TApp::GetApp()->DelWin(this);
		hWnd = NULL;

		if (!ret)
			return	FALSE;

	// shortcut の場合は、リンク先に飛ぶ
		if (!isLinkFile && (ext = strrchr(fname, '.')) && stricmp(ext, ".lnk") == 0) {
			char	arg[MAX_BUF];
			if (ReadLinkU8(fname, last_dir, arg)) {
				if ((GetFileAttributesU8(last_dir) & FILE_ATTRIBUTE_DIRECTORY) == 0)
					GetParentDir(last_dir, last_dir);
			}
			continue;
		}

		fileInfo = shareInfo->fileInfo[offset];

		PathToDir(fname, last_dir);
		ForcePathToFname(fname, fname);
		fileInfo->SetSelected(TRUE);

	// 上書き確認
		for (int i=0; i < shareInfo->fileCnt; i++)
		{
			if (!shareInfo->fileInfo[i]->IsSelected())
				continue;
			MakePath(buf, last_dir, offset == i ? fname : shareInfo->fileInfo[i]->Fname());
			if (GetFileAttributesU8(buf) != 0xffffffff)
			{
				ret = parentWin->MessageBoxU8(GetLoadStrU8(IDS_OVERWRITE), GetLoadStrU8(IDS_ATTENTION), MB_OKCANCEL|MB_ICONEXCLAMATION);
				if (ret != IDOK) {
					for (int j=0; j < shareInfo->fileCnt; j++)
						shareInfo->fileInfo[j]->SetSelected(FALSE);
				}
				break;
			}
		}
		if (ret) {
			fileInfo->SetFname(fname);
			strcpy(cfg->lastSaveDir, last_dir);
			cfg->WriteRegistry(CFG_GENERAL);
			return	TRUE;
		}
	}
	// not reach
}
Esempio n. 5
0
void CWedDoc::SaveBackup(const char *docname)

{
	CString	 num, filename = docname;
    PathToFname(filename);

	if(access(docname, 0) < 0)
		{
		num.Format("File %s does not exist, did make auto backup ", filename);
		message(num);
		//AfxMessageBox(num);
		return;
		}

	// Save only if smaller then 2 Meg
	if(docstat.st_size > MAX_BACKUP)
		{
		num.Format("File is too large for auto backup ", filename);
		message(num);
		return;
		}

	// Truncate up tp the first backslash
	int idx; CString tfn(docname);

	idx = tfn.Find("\\\\");
	if(idx >= 0)
		{
		tfn = tfn.Right(tfn.GetLength() - (idx + 1) );
		}
	else
		{
		idx = tfn.Find('\\');
		if(idx >= 0)
			{
			tfn = tfn.Right(tfn.GetLength() - (idx) );
			}
		}

	CString fbackup;
	//int hhh = HashString(docname);

	fbackup.Format("%sbackup%s", dataroot, tfn);
	create_full_dir(fbackup);

	CString fbdir(fbackup);
	PathToDir(fbdir);
	fbdir += "history\\"; fbdir += filename;

	//P2N("Sent backup copy to: %s\r\n", fbackup);

	// See if backup file exists already
    struct _stat docstat_o, docstat_b;

	_stat(docname, &docstat_o);

	CTime ct(docstat_o.st_mtime);
	CString datestr = ct.Format(".%a_%b_%d_%Y--%H_%M");
	fbdir += datestr;

	//P2N("Sent backup history to: %s\r\n", fbdir);

	// If backup is less than ....
	if(_stat(fbackup, &docstat_b) >=0)
		{
		//P2N("Document %s m_time=%d BackupFile m_time=%d \r\n",
        //              docname, docstat_o.st_mtime,  docstat_b.st_mtime );

		//if((docstat_o.st_mtime -  docstat_b.st_mtime) > 10)
			{
			//P2N("***Backing up: %s\r\n", fbackup);
			create_full_dir(fbdir);
			rename(fbackup, fbdir);
			}
		}

 	CFile cf;
	if(cf.Open(fbackup, CFile::modeCreate | CFile::modeWrite ))
		{
		num.Format("Saving backup copy %s ", filename);
		message(num);
		CArchive ar(&cf, CArchive::store);
		Serialize(ar, fbackup);
		}
	else
		{
		num.Format("Could not create backup copy of %s ", filename);
		message(num);
		//P2N("Cannot create backup copy of: %s\r\n", droot);
		}
}
Esempio n. 6
0
BOOL TRecvDlg::RecvDirFile(void)
{
#define BIG_ALLOC	50
#define PEEK_SIZE	8

	if (fileObj->status == FS_DIRFILESTART || fileObj->status == FS_TRANSINFO)
	{
		int		size;
		if (fileObj->infoLen == 0)
		{
			if ((size = ::recv(fileObj->conInfo->sd, fileObj->info + (int)fileObj->offset, PEEK_SIZE - (int)fileObj->offset, 0)) <= 0)
				return	FALSE;
			if ((fileObj->offset += size) < PEEK_SIZE)
				return	TRUE;
			fileObj->info[fileObj->offset] = 0;
			if ((fileObj->infoLen = strtoul(fileObj->info, 0, 16)) >= sizeof(fileObj->info) -1 || fileObj->infoLen <= 0)
				return	FALSE;	// too big or small
		}
		if (fileObj->offset < fileObj->infoLen)
		{
			if ((size = ::recv(fileObj->conInfo->sd, fileObj->info + (int)fileObj->offset, fileObj->infoLen - (int)fileObj->offset, 0)) <= 0)
				return	FALSE;
			fileObj->offset += size;
		}
		if (fileObj->offset == fileObj->infoLen)
		{
			fileObj->info[fileObj->infoLen] = 0;
			if (DecodeDirEntry(fileObj->info, &fileObj->curFileInfo, fileObj->u8fname) == FALSE)
				return	FALSE;	// Illegal entry
			fileObj->offset = fileObj->infoLen = 0;	// 初期化

			if (GET_MODE(fileObj->curFileInfo.Attr()) == IPMSG_FILE_DIR)
			{
				char	buf[MAX_BUF];
				const char *fname = fileObj->dirCnt == 0 ? fileObj->fileInfo->Fname() : fileObj->curFileInfo.Fname();

				if (MakePath(buf, fileObj->path, fname) >= MAX_PATH_U8)
					return	MessageBoxU8(buf, GetLoadStrU8(IDS_PATHTOOLONG)), FALSE;
				if (IsSafePath(buf, fname) == FALSE)
					return	FALSE;

				if (CreateDirectoryU8(buf, NULL) == FALSE)
					return	FALSE;
				strncpyz(fileObj->path, buf, MAX_PATH_U8);
				fileObj->dirCnt++;
			}
			else if (GET_MODE(fileObj->curFileInfo.Attr()) == IPMSG_FILE_RETPARENT)
			{
				if (fileObj->curFileInfo.Mtime())	// directory の time stamp をあわせる(NT系のみ)
				{
					FILETIME	ft;
					HANDLE		hFile;
					UnixTime2FileTime(fileObj->curFileInfo.Mtime(), &ft);
					if ((hFile = CreateFileU8(fileObj->path, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)) != INVALID_HANDLE_VALUE)
					{
						::SetFileTime(hFile, NULL, NULL, &ft);
						::CloseHandle(hFile);
					}
				}
				if (fileObj->curFileInfo.Attr() & IPMSG_FILE_RONLYOPT)
				SetFileAttributesU8(fileObj->path, FILE_ATTRIBUTE_READONLY);
				if (--fileObj->dirCnt <= 0)
				{
					fileObj->status = FS_COMPLETE;
					return	TRUE;
				}
				if (PathToDir(fileObj->path, fileObj->path) == FALSE)
					return	FALSE;
			}
			else {
				if (fileObj->dirCnt == 0)
					return	FALSE;
				
				if (fileObj->curFileInfo.Size() == 0)	// 0byte file
				{
					if (OpenRecvFile())		// 0byteの場合は作成失敗を無視
						CloseRecvFile(TRUE);
				}
				fileObj->status = fileObj->curFileInfo.Size() ? FS_TRANSFILE : FS_TRANSINFO;
			}
			return	TRUE;
		}
	}

	if (fileObj->status == FS_TRANSFILE)
	{
		if (RecvFile() != TRUE)
		{
			CloseRecvFile();
			return	FALSE;
		}
		if (fileObj->status == FS_ENDFILE)
		{
			CloseRecvFile(TRUE);
			fileObj->status = FS_TRANSINFO;
		}
	}

	return	TRUE;
}