mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[misc] move I/O functions into their own source
This commit is contained in:
		
							parent
							
								
									08d68301cd
								
							
						
					
					
						commit
						bc252400a1
					
				
					 9 changed files with 148 additions and 112 deletions
				
			
		|  | @ -153,6 +153,7 @@ | ||||||
|     <ClCompile Include="..\file.c" /> |     <ClCompile Include="..\file.c" /> | ||||||
|     <ClCompile Include="..\msdos.c" /> |     <ClCompile Include="..\msdos.c" /> | ||||||
|     <ClCompile Include="..\rufus.c" /> |     <ClCompile Include="..\rufus.c" /> | ||||||
|  |     <ClCompile Include="..\stdio.c" /> | ||||||
|     <ClCompile Include="..\stdlg.c" /> |     <ClCompile Include="..\stdlg.c" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|  |  | ||||||
|  | @ -42,6 +42,9 @@ | ||||||
|     <ClCompile Include="..\fat12.c"> |     <ClCompile Include="..\fat12.c"> | ||||||
|       <Filter>Source Files</Filter> |       <Filter>Source Files</Filter> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|  |     <ClCompile Include="..\stdio.c"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <ClInclude Include="..\rufus.h"> |     <ClInclude Include="..\rufus.h"> | ||||||
|  |  | ||||||
|  | @ -24,6 +24,7 @@ TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \ | ||||||
| SXS_APPLICATION_MANIFEST=common_controls_and_elevation.manifest | SXS_APPLICATION_MANIFEST=common_controls_and_elevation.manifest | ||||||
| 
 | 
 | ||||||
| SOURCES=rufus.c \ | SOURCES=rufus.c \ | ||||||
|  |         stdio.c \ | ||||||
|         stdlg.c \ |         stdlg.c \ | ||||||
|         msdos.c \ |         msdos.c \ | ||||||
|         file.c  \ |         file.c  \ | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -17,7 +17,7 @@ | ||||||
| # along with this program; if not, see <http://www.gnu.org/licenses/>.
 | # along with this program; if not, see <http://www.gnu.org/licenses/>.
 | ||||||
| #
 | #
 | ||||||
| 
 | 
 | ||||||
| OBJECTS   = fat12.o fat16.o fat32.o br.o file.o msdos.o stdlg.o rufus.o   | OBJECTS   = fat12.o fat16.o fat32.o br.o file.o msdos.o stdio.o stdlg.o rufus.o   | ||||||
| TARGET    = rufus | TARGET    = rufus | ||||||
| 
 | 
 | ||||||
| CC        = gcc | CC        = gcc | ||||||
|  |  | ||||||
							
								
								
									
										76
									
								
								rufus.c
									
										
									
									
									
								
							
							
						
						
									
										76
									
								
								rufus.c
									
										
									
									
									
								
							|  | @ -102,82 +102,6 @@ static HWND hDeviceTooltip = NULL, hFSTooltip = NULL; | ||||||
| static StrArray DriveID, DriveLabel; | static StrArray DriveID, DriveLabel; | ||||||
| static DWORD FormatStatus; | static DWORD FormatStatus; | ||||||
| 
 | 
 | ||||||
| #ifdef RUFUS_DEBUG |  | ||||||
| void _uprintf(const char *format, ...) |  | ||||||
| { |  | ||||||
| 	char buf[4096], *p = buf; |  | ||||||
| 	va_list args; |  | ||||||
| 	int n; |  | ||||||
| 
 |  | ||||||
| 	va_start(args, format); |  | ||||||
| 	n = safe_vsnprintf(p, sizeof(buf)-3, format, args); // buf-3 is room for CR/LF/NUL
 |  | ||||||
| 	va_end(args); |  | ||||||
| 
 |  | ||||||
| 	p += (n < 0)?sizeof(buf)-3:n; |  | ||||||
| 
 |  | ||||||
| 	while((p>buf) && (isspace(p[-1]))) |  | ||||||
| 		*--p = '\0'; |  | ||||||
| 
 |  | ||||||
| 	*p++ = '\r'; |  | ||||||
| 	*p++ = '\n'; |  | ||||||
| 	*p   = '\0'; |  | ||||||
| 
 |  | ||||||
| 	OutputDebugStringA(buf); |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| void DumpBufferHex(void *buf, size_t size) |  | ||||||
| { |  | ||||||
| 	unsigned char* buffer = (unsigned char*)buf; |  | ||||||
| 	size_t i, j, k; |  | ||||||
| 	char line[80] = ""; |  | ||||||
| 
 |  | ||||||
| 	for (i=0; i<size; i+=16) { |  | ||||||
| 		if (i!=0) |  | ||||||
| 			uprintf("%s\n", line); |  | ||||||
| 		line[0] = 0; |  | ||||||
| 		sprintf(&line[strlen(line)], "  %08x  ", (unsigned int)i); |  | ||||||
| 		for(j=0,k=0; k<16; j++,k++) { |  | ||||||
| 			if (i+j < size) { |  | ||||||
| 				sprintf(&line[strlen(line)], "%02x", buffer[i+j]); |  | ||||||
| 			} else { |  | ||||||
| 				sprintf(&line[strlen(line)], "  "); |  | ||||||
| 			} |  | ||||||
| 			sprintf(&line[strlen(line)], " "); |  | ||||||
| 		} |  | ||||||
| 		sprintf(&line[strlen(line)], " "); |  | ||||||
| 		for(j=0,k=0; k<16; j++,k++) { |  | ||||||
| 			if (i+j < size) { |  | ||||||
| 				if ((buffer[i+j] < 32) || (buffer[i+j] > 126)) { |  | ||||||
| 					sprintf(&line[strlen(line)], "."); |  | ||||||
| 				} else { |  | ||||||
| 					sprintf(&line[strlen(line)], "%c", buffer[i+j]); |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	uprintf("%s\n", line); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void PrintStatus(const char *format, ...) |  | ||||||
| { |  | ||||||
| 	char buf[256], *p = buf; |  | ||||||
| 	va_list args; |  | ||||||
| 	int n; |  | ||||||
| 
 |  | ||||||
| 	va_start(args, format); |  | ||||||
| 	n = safe_vsnprintf(p, sizeof(buf)-1, format, args); // room for NUL
 |  | ||||||
| 	va_end(args); |  | ||||||
| 
 |  | ||||||
| 	p += (n < 0)?sizeof(buf)-1:n; |  | ||||||
| 
 |  | ||||||
| 	while((p>buf) && (isspace(p[-1]))) |  | ||||||
| 		*--p = '\0'; |  | ||||||
| 
 |  | ||||||
| 	*p   = '\0'; |  | ||||||
| 
 |  | ||||||
| 	SetDlgItemTextU(hMainDialog, IDC_STATUS, buf); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  * Convert a partition type to its human readable form using |  * Convert a partition type to its human readable form using | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								rufus.h
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								rufus.h
									
										
									
									
									
								
							|  | @ -75,6 +75,8 @@ extern char szFolderPath[MAX_PATH]; | ||||||
|  * Shared prototypes |  * Shared prototypes | ||||||
|  */ |  */ | ||||||
| extern char *WindowsErrorString(void); | extern char *WindowsErrorString(void); | ||||||
|  | extern void DumpBufferHex(void *buf, size_t size); | ||||||
|  | extern void PrintStatus(const char *format, ...); | ||||||
| extern void CenterDialog(HWND hDlg); | extern void CenterDialog(HWND hDlg); | ||||||
| extern void CreateStatusBar(void); | extern void CreateStatusBar(void); | ||||||
| extern INT_PTR CreateAboutBox(void); | extern INT_PTR CreateAboutBox(void); | ||||||
|  |  | ||||||
							
								
								
									
										12
									
								
								rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								rufus.rc
									
										
									
									
									
								
							|  | @ -63,7 +63,7 @@ BEGIN | ||||||
|     DEFPUSHBUTTON   "OK",IDOK,231,175,50,14,WS_GROUP |     DEFPUSHBUTTON   "OK",IDOK,231,175,50,14,WS_GROUP | ||||||
|     CONTROL         "<a href=""https://github.com/pbatard/rufus/wiki/Rufus"">https://github.com/pbatard/rufus</a>",IDC_ABOUT_RUFUS_URL, |     CONTROL         "<a href=""https://github.com/pbatard/rufus/wiki/Rufus"">https://github.com/pbatard/rufus</a>",IDC_ABOUT_RUFUS_URL, | ||||||
|                     "SysLink",WS_TABSTOP,46,47,114,9 |                     "SysLink",WS_TABSTOP,46,47,114,9 | ||||||
|     LTEXT           "Version 1.0.0 (Build 56)",IDC_STATIC,46,19,78,8 |     LTEXT           "Version 1.0.0 (Build 57)",IDC_STATIC,46,19,78,8 | ||||||
|     PUSHBUTTON      "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP |     PUSHBUTTON      "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP | ||||||
|     EDITTEXT        IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL |     EDITTEXT        IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL | ||||||
|     LTEXT           "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 |     LTEXT           "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8 | ||||||
|  | @ -162,8 +162,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 1,0,0,56 |  FILEVERSION 1,0,0,57 | ||||||
|  PRODUCTVERSION 1,0,0,56 |  PRODUCTVERSION 1,0,0,57 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -180,13 +180,13 @@ BEGIN | ||||||
|         BEGIN |         BEGIN | ||||||
|             VALUE "CompanyName", "akeo.ie" |             VALUE "CompanyName", "akeo.ie" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "1.0.0.56" |             VALUE "FileVersion", "1.0.0.57" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)" | ||||||
|             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" |             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" | ||||||
|             VALUE "OriginalFilename", "rufus.exe" |             VALUE "OriginalFilename", "rufus.exe" | ||||||
|             VALUE "ProductName", "Rufus" |             VALUE "ProductName", "Rufus" | ||||||
|             VALUE "ProductVersion", "1.0.0.56" |             VALUE "ProductVersion", "1.0.0.57" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  | @ -212,7 +212,7 @@ IDI_ICON                ICON                    "rufus.ico" | ||||||
| 
 | 
 | ||||||
| STRINGTABLE | STRINGTABLE | ||||||
| BEGIN | BEGIN | ||||||
|     IDS_VERSION             "Rufus v1.0.0.56" |     IDS_VERSION             "Rufus v1.0.0.57" | ||||||
| END | END | ||||||
| 
 | 
 | ||||||
| #endif    // English resources | #endif    // English resources | ||||||
|  |  | ||||||
							
								
								
									
										134
									
								
								stdio.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								stdio.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,134 @@ | ||||||
|  | /*
 | ||||||
|  |  * Rufus: The Resourceful USB Formatting Utility | ||||||
|  |  * Standard I/O Routines (logging, status, etc.) | ||||||
|  |  * Copyright (c) 2011 Pete Batard <pete@akeo.ie> | ||||||
|  |  * | ||||||
|  |  * This program is free software: you can redistribute it and/or modify | ||||||
|  |  * it under the terms of the GNU General Public License as published by | ||||||
|  |  * the Free Software Foundation, either version 3 of the License, or | ||||||
|  |  * (at your option) any later version. | ||||||
|  |  * | ||||||
|  |  * This program is distributed in the hope that it will be useful, | ||||||
|  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||||
|  |  * GNU General Public License for more details. | ||||||
|  |  * | ||||||
|  |  * You should have received a copy of the GNU General Public License | ||||||
|  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #include <windows.h> | ||||||
|  | #include <stdio.h> | ||||||
|  | #include <string.h> | ||||||
|  | #include <stdlib.h> | ||||||
|  | #include <ctype.h> | ||||||
|  | 
 | ||||||
|  | #include "msapi_utf8.h" | ||||||
|  | #include "rufus.h" | ||||||
|  | #include "resource.h" | ||||||
|  | 
 | ||||||
|  | #ifdef RUFUS_DEBUG | ||||||
|  | void _uprintf(const char *format, ...) | ||||||
|  | { | ||||||
|  | 	char buf[4096], *p = buf; | ||||||
|  | 	va_list args; | ||||||
|  | 	int n; | ||||||
|  | 
 | ||||||
|  | 	va_start(args, format); | ||||||
|  | 	n = safe_vsnprintf(p, sizeof(buf)-3, format, args); // buf-3 is room for CR/LF/NUL
 | ||||||
|  | 	va_end(args); | ||||||
|  | 
 | ||||||
|  | 	p += (n < 0)?sizeof(buf)-3:n; | ||||||
|  | 
 | ||||||
|  | 	while((p>buf) && (isspace(p[-1]))) | ||||||
|  | 		*--p = '\0'; | ||||||
|  | 
 | ||||||
|  | 	*p++ = '\r'; | ||||||
|  | 	*p++ = '\n'; | ||||||
|  | 	*p   = '\0'; | ||||||
|  | 
 | ||||||
|  | 	OutputDebugStringA(buf); | ||||||
|  | } | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
|  | void DumpBufferHex(void *buf, size_t size) | ||||||
|  | { | ||||||
|  | 	unsigned char* buffer = (unsigned char*)buf; | ||||||
|  | 	size_t i, j, k; | ||||||
|  | 	char line[80] = ""; | ||||||
|  | 
 | ||||||
|  | 	for (i=0; i<size; i+=16) { | ||||||
|  | 		if (i!=0) | ||||||
|  | 			uprintf("%s\n", line); | ||||||
|  | 		line[0] = 0; | ||||||
|  | 		sprintf(&line[strlen(line)], "  %08x  ", (unsigned int)i); | ||||||
|  | 		for(j=0,k=0; k<16; j++,k++) { | ||||||
|  | 			if (i+j < size) { | ||||||
|  | 				sprintf(&line[strlen(line)], "%02x", buffer[i+j]); | ||||||
|  | 			} else { | ||||||
|  | 				sprintf(&line[strlen(line)], "  "); | ||||||
|  | 			} | ||||||
|  | 			sprintf(&line[strlen(line)], " "); | ||||||
|  | 		} | ||||||
|  | 		sprintf(&line[strlen(line)], " "); | ||||||
|  | 		for(j=0,k=0; k<16; j++,k++) { | ||||||
|  | 			if (i+j < size) { | ||||||
|  | 				if ((buffer[i+j] < 32) || (buffer[i+j] > 126)) { | ||||||
|  | 					sprintf(&line[strlen(line)], "."); | ||||||
|  | 				} else { | ||||||
|  | 					sprintf(&line[strlen(line)], "%c", buffer[i+j]); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	uprintf("%s\n", line); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /*
 | ||||||
|  |  * Convert a windows error to human readable string | ||||||
|  |  * uses retval as errorcode, or, if 0, use GetLastError() | ||||||
|  |  */ | ||||||
|  | char *WindowsErrorString(void) | ||||||
|  | { | ||||||
|  | static char err_string[256]; | ||||||
|  | 
 | ||||||
|  | 	DWORD size; | ||||||
|  | 	DWORD error_code, format_error; | ||||||
|  | 
 | ||||||
|  | 	error_code = GetLastError(); | ||||||
|  | 
 | ||||||
|  | 	safe_sprintf(err_string, sizeof(err_string), "[%d] ", error_code); | ||||||
|  | 
 | ||||||
|  | 	size = FormatMessageU(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code, | ||||||
|  | 		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &err_string[strlen(err_string)], | ||||||
|  | 		sizeof(err_string)-(DWORD)strlen(err_string), NULL); | ||||||
|  | 	if (size == 0) { | ||||||
|  | 		format_error = GetLastError(); | ||||||
|  | 		if (format_error) | ||||||
|  | 			safe_sprintf(err_string, sizeof(err_string), | ||||||
|  | 				"Windows error code %u (FormatMessage error code %u)", error_code, format_error); | ||||||
|  | 		else | ||||||
|  | 			safe_sprintf(err_string, sizeof(err_string), "Unknown error code %u", error_code); | ||||||
|  | 	} | ||||||
|  | 	return err_string; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void PrintStatus(const char *format, ...) | ||||||
|  | { | ||||||
|  | 	char buf[256], *p = buf; | ||||||
|  | 	va_list args; | ||||||
|  | 	int n; | ||||||
|  | 
 | ||||||
|  | 	va_start(args, format); | ||||||
|  | 	n = safe_vsnprintf(p, sizeof(buf)-1, format, args); // room for NUL
 | ||||||
|  | 	va_end(args); | ||||||
|  | 
 | ||||||
|  | 	p += (n < 0)?sizeof(buf)-1:n; | ||||||
|  | 
 | ||||||
|  | 	while((p>buf) && (isspace(p[-1]))) | ||||||
|  | 		*--p = '\0'; | ||||||
|  | 
 | ||||||
|  | 	*p   = '\0'; | ||||||
|  | 
 | ||||||
|  | 	SetDlgItemTextU(hMainDialog, IDC_STATUS, buf); | ||||||
|  | } | ||||||
							
								
								
									
										29
									
								
								stdlg.c
									
										
									
									
									
								
							
							
						
						
									
										29
									
								
								stdlg.c
									
										
									
									
									
								
							|  | @ -75,35 +75,6 @@ static HWND hBrowseEdit; | ||||||
| static WNDPROC pOrgBrowseWndproc; | static WNDPROC pOrgBrowseWndproc; | ||||||
| HFONT hBoldFont = NULL; | HFONT hBoldFont = NULL; | ||||||
| 
 | 
 | ||||||
| /*
 |  | ||||||
|  * Convert a windows error to human readable string |  | ||||||
|  * uses retval as errorcode, or, if 0, use GetLastError() |  | ||||||
|  */ |  | ||||||
| char *WindowsErrorString(void) |  | ||||||
| { |  | ||||||
| static char err_string[256]; |  | ||||||
| 
 |  | ||||||
| 	DWORD size; |  | ||||||
| 	DWORD error_code, format_error; |  | ||||||
| 
 |  | ||||||
| 	error_code = GetLastError(); |  | ||||||
| 
 |  | ||||||
| 	safe_sprintf(err_string, sizeof(err_string), "[%d] ", error_code); |  | ||||||
| 
 |  | ||||||
| 	size = FormatMessageU(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code, |  | ||||||
| 		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &err_string[strlen(err_string)], |  | ||||||
| 		sizeof(err_string)-(DWORD)strlen(err_string), NULL); |  | ||||||
| 	if (size == 0) { |  | ||||||
| 		format_error = GetLastError(); |  | ||||||
| 		if (format_error) |  | ||||||
| 			safe_sprintf(err_string, sizeof(err_string), |  | ||||||
| 				"Windows error code %u (FormatMessage error code %u)", error_code, format_error); |  | ||||||
| 		else |  | ||||||
| 			safe_sprintf(err_string, sizeof(err_string), "Unknown error code %u", error_code); |  | ||||||
| 	} |  | ||||||
| 	return err_string; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /*
 | /*
 | ||||||
|  * Detect Windows version |  * Detect Windows version | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue