static void get_group_name( char *buff, char *group ) { LPITEMIDLIST ppidl; if( SHGetSpecialFolderLocation( NULL, CSIDL_PROGRAMS, &ppidl ) == NOERROR ) { SHGetPathFromIDList( ppidl, buff ); } else { GetWindowsDirectory( buff, _MAX_PATH ); strcat( buff, "\\Start Menu\\Programs" ); } strcat( buff, "\\" ); strcat( buff, group ); munge_fname( buff ); }
static BOOL create_icon( char *group, char *pgm, char *desc, char *arg, char *work, char *icon, int icon_num ) { HRESULT hres; IShellLink *m_link; IPersistFile *p_file; WORD w_link[_MAX_PATH]; char link[_MAX_PATH]; // Determine names of link files get_group_name( link, group ); strcat( link, "\\" ); strcat( link, desc ); strcat( link, ".lnk" ); munge_fname( link ); MultiByteToWideChar( CP_ACP, 0, link, -1, w_link, _MAX_PATH ); // Create an IShellLink object and get a pointer to the IShellLink interface m_link = NULL; hres = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void **)&m_link ); if( SUCCEEDED( hres ) ) { // Query IShellLink for the IPersistFile interface for // saving the shortcut in persistent storage. p_file = NULL; hres = m_link->lpVtbl->QueryInterface( m_link, &IID_IPersistFile, (void **)&p_file ); if( SUCCEEDED( hres ) ) { // Set the properties of the shortcut hres = m_link->lpVtbl->SetPath( m_link, pgm ); hres = m_link->lpVtbl->SetDescription( m_link, desc ); hres = m_link->lpVtbl->SetWorkingDirectory( m_link, work ); hres = m_link->lpVtbl->SetArguments( m_link, arg ); hres = m_link->lpVtbl->SetIconLocation( m_link, icon, icon_num ); // Save the shortcut via the IPersistFile::Save member function. hres = p_file->lpVtbl->Save( p_file, w_link, TRUE ); // Release the pointer to IPersistFile. p_file->lpVtbl->Release( p_file ); } // Release the pointer to IShellLink. m_link->lpVtbl->Release( m_link ); } return( SUCCEEDED( hres ) ); }
void file_write (File *file, const char* directory) { char *path = NULL; assert (file); if (!file) return; if (file->name == NULL) { file->name = strdup( TNEF_DEFAULT_FILENAME ); debug_print ("No file name specified, using default %s.\n", TNEF_DEFAULT_FILENAME); } if ( file->path == NULL ) { file->path = munge_fname( file->name ); if (file->path == NULL) { file->path = strdup( TNEF_DEFAULT_FILENAME ); debug_print ("No path name available, using default %s.\n", TNEF_DEFAULT_FILENAME); } } path = concat_fname( directory, file->path ); if (path == NULL) { path = strdup( TNEF_DEFAULT_FILENAME ); debug_print ("No path generated, using default %s.\n", TNEF_DEFAULT_FILENAME); } debug_print ("%sWRITING\t|\t%s\t|\t%s\n", ((LIST_ONLY==0)?"":"NOT "), file->name, path); if (!LIST_ONLY) { FILE *fp = NULL; if (!confirm_action ("extract %s?", file->name)) return; if (!OVERWRITE_FILES) { if (file_exists (path)) { if (!NUMBER_FILES) { fprintf (stderr, "tnef: %s: Could not create file: File exists\n", path); return; } else { char *tmp = find_free_number (path); debug_print ("Renaming %s to %s\n", path, tmp); XFREE (path); path = tmp; } } } fp = fopen (path, "wb"); if (fp == NULL) { perror (path); exit (1); } if (fwrite (file->data, 1, file->len, fp) != file->len) { perror (path); exit (1); } fclose (fp); } if (LIST_ONLY || VERBOSE_ON) { if (LIST_ONLY && VERBOSE_ON) { /* FIXME: print out date and stuff */ const char *date_str = date_to_str(&file->dt); fprintf (stdout, "%11lu\t|\t%s\t|\t%s\t|\t%s", (unsigned long)file->len, date_str+4, /* skip the day of week */ file->name, path); } else { fprintf (stdout, "%s\t|\t%s", file->name, path); } if ( SHOW_MIME ) { fprintf (stdout, "\t|\t%s", file->mime_type ? file->mime_type : "unknown"); fprintf (stdout, "\t|\t%s", file->content_id ? file->content_id : ""); } fprintf (stdout, "\n"); } XFREE(path); }