示例#1
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow) {

    gDebug = (getenv("ANDROID_SDKMAN_DEBUG") != NULL);

    PVOID oldWow64Value = disableWow64FsRedirection();

    CPath javaPath;
    if (!findJavaInEnvPath(&javaPath) &&
        !findJavaInRegistry(&javaPath) &&
        !findJavaInProgramFiles(&javaPath)) {
        msgBox("Failed to find Java on your system. Please reinstall it.");
        return 2;
    }
    _ASSERT(!javaPath.isEmpty());

    revertWow64FsRedirection(oldWow64Value);

    // For debugging it's convenient to override the tools directory location
    CPath toolsDir(getenv("ANDROID_SDKMAN_TOOLS_DIR"));
    if (toolsDir.isEmpty()) {
        if (!getModuleDir(&toolsDir)) {
            displayLastError("Failed to get program's filename: ");
            return 1;
        }
    }
    _ASSERT(!toolsDir.isEmpty());

    CPath tmpDir;
    if (!mkTempDir("temp-android-tool", &tmpDir)) {
        return 1;
    }
    _ASSERT(!tmpDir.isEmpty());

    if (!mkDirs(tmpDir.cstr(), sMkDirList)) {
        return 1;
    }

    if (!copyFiles(toolsDir.cstr(), tmpDir.cstr(), sFilesToCopy)) {
        return 1;
    }

    if (!execSdkManager(javaPath.cstr(), toolsDir.cstr(), tmpDir.cstr(), lpCmdLine)) {
        displayLastError("Failed to start SDK Manager: ");
        return 1;
    }

    return 0;
}
DWORD WINAPI decompress(LPVOID lParam/*char *archive_name*//*, vector<string> filenames*/){
    sTime = time(NULL);
	_filename = DECOMPRESS_PREPARING;

	setLang();
	
	char overwrite_mode = OVERWRITE_YES;
	//unsigned long uncompressed_bytes=0, compressed_bytes=0;  // Input, output sizes
    
    vector<string> filename;
    vector<__int64> filesize;

	char filebuff[32768];
    
    _size_all = 0;
    _done_all = 0;
    
    FILE* archive=fopen(archive_name, "rb");
    //MessageBox(0,archive_name,"",0);
    if(archive){
		_fseeki64(archive, 0LL, SEEK_END);
		_compressed /*= compressed_bytes*/=_ftelli64(archive);
		_fseeki64(archive, 0LL, SEEK_SET);
		
		if(tolower(archive_name[strlen(archive_name)-1]) == 'e' && tolower(archive_name[strlen(archive_name)-2]) == 'x' && tolower(archive_name[strlen(archive_name)-3]) == 'e'){
			char buff[2048];
			for(int i=0;!feof(archive);i++){
				fread(buff, sizeof(*buff), sizeof(buff)/sizeof(*buff), archive);
				if(cmp(PROGNAME, buff)){
					_fseeki64(archive, i*2048, SEEK_SET);
					break;
				}else if(cmp("ENC", buff)){
					//tu nic nie robimy, to sie zrobi gdzies wczesniej
				}
			}
			//_fseeki64(archive, SFX_OFFSET, SEEK_SET);
			//_compressed -= SFX_OFFSET;
			sfx_arch = true;
		}

		//MessageBox(0, "", "", 0);

        string s=getline(archive);
        if (s.substr(0, string(PROGNAME).size()) != PROGNAME) {
           //printf("Archiwum %s nie jest w formacie " PROGNAME "\n", argv[1]);
           return false;
        }
    
        // Get option -m where m is a digit
        if (s.size()>2 && s[s.size()-2]=='-') {
           int c=s[s.size()-1];
           if (c>='0' && c<='9')
               MEM=c-'0';
        }
        
        // Read "size filename" in "%d\t%s\r\n" format
        while (true) {
              string s=getline(archive);
			  __int64 tmpSize;
			  sscanf(s.c_str(), "%lld", &tmpSize);
              if (s.size()>1) {
                 filesize.push_back(/*atol(s.c_str())*/tmpSize);
                 
                 _size_all += tmpSize;//atol(s.c_str());
                 
                 string::iterator tab=find(s.begin(), s.end(), '\t');
                 if (tab!=s.end())
                    filename.push_back(string(tab+1, s.end()));
                 else
                    filename.push_back("");
              }
              else
                  break;
        }
        
        // Test end of header for "\f\0"
        {
           int c1=0, c2=0;
           if ((c1=getc(archive))!='\f' || (c2=getc(archive))!=0) {
              //printf("%s: Zly format naglowka pliku %d %d\n", argv[1],
              //c1, c2);
              return false;
           }
        }

		_filename = DECOMPRESS_CREATING_DIRS;
		if(files4decompress.size() != 0)
			mkDirs(files4decompress);
		else
			mkDirs(filename);
        
         // Extract files from archive data
         Transformer e(DECOMPRESS, archive);
         
         for (int i=0; i<int(filename.size()); ++i) {
             
             _filename = filename[i];
             
             const __int64 size=filesize[i];
             //uncompressed_bytes+=size;
             _size = size;
             
             FILE *f=NULL;//=fopen(filename[i].c_str(), "wb");
 
			 if(files4decompress.size() != 0){
				//MessageBox(0, "", "", 0);
				for(int j=0;j<files4decompress.size();j++){
					if(filename[i] == files4decompress[j]){
						if(_access(filename[i].c_str(), 4) == 0){
							/*char errMSG[512];
							sprintf(errMSG, loadString(IDS_FILE_ALREADY_EXISTS), filename[i].c_str());
							if(MessageBox(0, errMSG, "KGB Archiver", MB_YESNO) == IDNO){
								break;
							}*/
							if(overwrite_mode != OVERWRITE_YES_ALL && overwrite_mode != OVERWRITE_NO_ALL)
								overwrite_mode = overwrite(filename[i], filesize[i]);
							if(overwrite_mode == OVERWRITE_NO || overwrite_mode == OVERWRITE_NO_ALL)
								break;
						}
						/*security update, thanks to Joxean Koret*/
						if(!dirSecurityCheck(filename[i])){
							_filename = DECOMPRESS_SKIPPING;
						}else
							f = fopen(filename[i].c_str(), "wb");
						break;
					}
				}
				if(f == NULL)
					_filename = DECOMPRESS_SKIPPING;
			 }else{
				 //bool overwrite = true;
				 if(overwrite_mode == OVERWRITE_NO)
					 overwrite_mode = OVERWRITE_YES;
				 if(_access(filename[i].c_str(), 4) == 0){
					/*char errMSG[512];
					sprintf(errMSG, loadString(IDS_FILE_ALREADY_EXISTS), filename[i].c_str());
					if(MessageBox(0, errMSG, "KGB Archiver", MB_YESNO) == IDNO){
						_filename = DECOMPRESS_SKIPPING;
						overwrite = false;
					}*/
					 if(overwrite_mode != OVERWRITE_YES_ALL && overwrite_mode != OVERWRITE_NO_ALL)
						overwrite_mode = overwrite(filename[i], filesize[i]);
					 if(overwrite_mode == OVERWRITE_NO || overwrite_mode == OVERWRITE_NO_ALL)
						_filename = DECOMPRESS_SKIPPING;
				 }
				 if((overwrite_mode == OVERWRITE_YES || overwrite_mode == OVERWRITE_YES_ALL) || _access(filename[i].c_str(), 4) != NULL){
					/*security update, thanks to Joxean Koret*/
					 if(!dirSecurityCheck(filename[i])){
						_filename = DECOMPRESS_SKIPPING;
					}else
						f = fopen(filename[i].c_str(), "wb");
				 }
			 }

			 if (f){
				 setvbuf(f, filebuff, _IOFBF, sizeof(filebuff));
             }
             for (unsigned long j=0; j<size; ++j) {
                 int c=e.decode();
                 if (f)
                    putc(c, f);
                 _done = j;
             }
             if (f) {
                 //printf("wypakowany\n");
                 fclose(f);
             }
             
			 _done_all += _size;
         }
         
         fclose(archive);
         
    }else
       return false;
       
    return true; 
}