Main Page   File List   Globals  

utils.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2002 Ingo Richter and others.
00003  * All rights reserved.   This program and the accompanying materials
00004  * are made available under the terms of the Common Public License v1.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.eclipse.org/legal/cpl-v10.html
00007  * 
00008  * Contributors:
00009  *    Ingo Richter - Initial implementation.
00010  */
00011 #define strict
00012 
00013 #include <windows.h>
00014 #include <shlobj.h>
00015 
00016 #include "utils.h"
00017 
00018 /*
00019  * Describe here
00020  * @param MatchType
00021  * @param MatchFile
00022  * @param fileName
00023  */
00024 int GetOpenFilename(TCHAR *MatchType, TCHAR *MatchFile, TCHAR* fileName)
00025 {
00026    OPENFILENAME fn;
00027    register int i;
00028    char Filter[128];
00029    TCHAR DefaultFile[512];
00030 
00031    // construct file name filter string
00032    lstrcpy(Filter, MatchType);
00033    i = lstrlen(Filter) + 1;
00034    lstrcpy(&Filter[i],MatchFile);
00035    i += lstrlen(&Filter[i]) + 1;
00036    Filter[i] = '\0';
00037 
00038    // fill in structure fields for Open File dialog box
00039    fn.lStructSize       = sizeof(OPENFILENAME);
00040    fn.hwndOwner         = GetActiveWindow();
00041    fn.lpstrFilter       = Filter;
00042    fn.lpstrCustomFilter = NULL;
00043    fn.nFilterIndex      = 0;
00044    fn.lpstrFile         = NULL;
00045    fn.lpstrFile         = DefaultFile;
00046    fn.nMaxFile          = sizeof(DefaultFile);
00047    fn.lpstrFileTitle    = NULL;
00048    fn.lpstrInitialDir   = NULL;
00049    fn.lpstrTitle        = NULL;
00050    fn.Flags             = OFN_READONLY;
00051    fn.lpstrDefExt       = &MatchFile[2];
00052    *DefaultFile = '\0';
00053 
00054    // activate the Open File dialog box
00055    if (GetOpenFileName(&fn))
00056    {
00057       lstrcpy(fileName, DefaultFile);
00058       return TRUE;
00059    }
00060    else
00061       return FALSE;
00062 }
00063 
00064 /*
00065  * Describe here
00066  * @param fileName
00067  */
00068 void GetFolderName(TCHAR* fileName)
00069 {
00070     TCHAR path[MAX_PATH];
00071     LPITEMIDLIST pidl;
00072 
00073     BROWSEINFO bi = { 0 };
00074     bi.lpszTitle = "Select your Workspace";
00075     bi.pszDisplayName = path;
00076     bi.ulFlags = BIF_RETURNONLYFSDIRS;
00077 
00078     pidl = SHBrowseForFolder ( &bi );
00079     if ( pidl != 0 )
00080     {
00081         TCHAR szDir[MAX_PATH];
00082         if( SHGetPathFromIDList( pidl, szDir ) )
00083         {
00084             strcpy(fileName, szDir);
00085         }
00086     }
00087 }
00088 
00098 BOOL lockfileIsDeleteable(TCHAR* pathToWorkspace)
00099 {
00100     TCHAR path[MAX_PATH];
00101 
00102     wsprintf(path, "%s\\.metadata\\.lock", pathToWorkspace);
00103     if(DeleteFile(path))
00104     {
00105         return FALSE;
00106     }
00107     else
00108     {
00109         return TRUE;
00110     }
00111 }
00112 
00113 /*
00114  * Describe here
00115  * @param messageId
00116  * @param buffer
00117  */
00118 TCHAR* LocString(int messageId, TCHAR* buffer)
00119 {
00120     LoadString(getApplicationInstance(), messageId, buffer, STRINGBUFFER_SIZE);
00121 
00122     return(buffer);
00123 }
00124 
00125 /*
00126  * Return the instance Handle of the running Application.
00127  */
00128 HINSTANCE getApplicationInstance()
00129 {
00130     return GetModuleHandle(NULL);
00131 }

Generated on Sun Apr 6 13:49:03 2003 for EclipseLauncher by doxygen1.2.17