static void writeDone (CCSBackend *backend, CCSContext * context) { /* export the data to ensure the changes are on disk */ char *fileName; const char *currentProfileCCS; char *currentProfile; IniPrivData *data; data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return; currentProfileCCS = ccsGetProfile (context); if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else currentProfile = strdup (currentProfileCCS); fileName = getIniFileName (currentProfile); free (currentProfile); ccsIniSave (data->iniFile, fileName); ccsEnableFileWatch (data->iniWatchId); free (fileName); }
static void writeDone (CCSContext * context) { /* export the data to ensure the changes are on disk */ char *fileName; char *currentProfile; IniPrivData *data; data = findPrivFromContext (context); if (!data) return; currentProfile = ccsGetProfile (context); if (!currentProfile || !strlen (currentProfile)) currentProfile = strdup (DEFAULTPROF); else currentProfile = strdup (currentProfile); fileName = getIniFileName (currentProfile); free (currentProfile); ccsIniSave (data->iniFile, fileName); ccsEnableFileWatch (data->iniWatchId); free (fileName); }
INT_PTR onMoveDialogFinished (HWND hDlg, WPARAM wParam, LPARAM lParam) { TCHAR iniFileName [FM_MAX_PATH]; getIniFileName (iniFileName, sizeof (iniFileName)); saveDlgItemProperties (hDlg, IDD_COPY_PROGRESS, iniFileName); DestroyWindow (hDlg); removeOperationThread (hDlg); Task* copyTask = (Task*) lParam; delete copyTask; return 0; }
static void setProfile (IniPrivData *data, char *profile) { char *fileName; struct stat fileStat; if (data->iniFile) ccsIniClose (data->iniFile); if (data->iniWatchId) ccsRemoveFileWatch (data->iniWatchId); data->iniFile = NULL; data->iniWatchId = 0; /* first we need to find the file name */ fileName = getIniFileName (profile); if (!fileName) return; /* if the file does not exist, we have to create it */ if (stat (fileName, &fileStat) == -1) { if (errno == ENOENT) { FILE *file; file = fopen (fileName, "w"); if (!file) { free (fileName); return; } fclose (file); } else { free (fileName); return; } } data->iniWatchId = ccsAddFileWatch (fileName, TRUE, processFileEvent, data); /* load the data from the file */ data->iniFile = ccsIniOpen (fileName); free (fileName); }
static Bool deleteProfile (CCSBackend *backend, CCSContext * context, char * profile) { char *fileName; fileName = getIniFileName (profile); if (!fileName) return FALSE; remove (fileName); free (fileName); return TRUE; }
static void processFileEvent (unsigned int watchId, void *closure) { IniPrivData *data = (IniPrivData *) closure; char *fileName; /* our ini file has been modified, reload it */ if (data->iniFile) ccsIniClose (data->iniFile); fileName = getIniFileName (data->lastProfile); if (!fileName) return; data->iniFile = ccsIniOpen (fileName); ccsReadSettings (data->context); free (fileName); }
BOOL moveSelected (HWND hDlg, UINT fullPathIdSrc, UINT panelIdSrc, UINT fullPathIdDst, UINT panelIdDst) { TCHAR fileName [MAX_PATH]; LVITEM lvi; lvi.mask = LVIF_PARAM; lvi.iSubItem = 0; // Создать задание для копирования Task* copyTask = new Task (); Progress* progress = copyTask->getProgress(); // Создать список имён файлов из выделенных lvi.iItem = (int) SendDlgItemMessage (hDlg, panelIdSrc, LVM_GETNEXTITEM, (WPARAM)0, (LPARAM)LVNI_SELECTED); if (lvi.iItem == 0) return FALSE; while (lvi.iItem != -1) { SendDlgItemMessage (hDlg, panelIdSrc, LVM_GETITEM, 0, (LPARAM)&lvi); copyTask->addFileName (((WIN32_FIND_DATA*)lvi.lParam)->cFileName); lvi.iItem = (int) SendDlgItemMessage (hDlg, panelIdSrc, LVM_GETNEXTITEM, (WPARAM)lvi.iItem, (LPARAM)LVNI_SELECTED); fileName[0] = L'\0'; } // Папка источник SendDlgItemMessage (hDlg, fullPathIdSrc, WM_GETTEXT, sizeof(fileName), (LPARAM)fileName); copyTask->setSrcFolder (fileName); // Папка назначение SendDlgItemMessage (hDlg, fullPathIdDst, WM_GETTEXT, sizeof(fileName), (LPARAM)fileName); copyTask->setDstFolder (fileName); // Cоздать поток копирования в спящем состоянии HANDLE hCopyThread = CreateThread (NULL, NULL, moveFileWorker, copyTask, CREATE_SUSPENDED, NULL); if (hCopyThread == NULL) return FALSE; SetThreadPriority (hCopyThread, THREAD_PRIORITY_IDLE); // Создать диалог копирования LONG hInst = GetWindowLong (hDlg, GWL_HINSTANCE); progress->hDlg = CreateDialogParam ((HINSTANCE)hInst, MAKEINTRESOURCE(IDD_COPY_PROGRESS), hDlg, moveDlgProc, 0); if (progress->hDlg == NULL) return FALSE; SendMessage (progress->hDlg, WM_SETTEXT, 0, (LPARAM) L"Перемещение"); SendDlgItemMessage (progress->hDlg, IDC_COPY_DEST, WM_SETTEXT, 0, (LPARAM)copyTask->getDstFolder()); getIniFileName (fileName, sizeof (fileName)); loadDlgItemProperties (progress->hDlg, IDD_COPY_PROGRESS, fileName); // Сохранить дескрипторы диалога копирования и потока копирования setOperationThread (progress->hDlg, hCopyThread, TRUE); // Установить флаг активности операции перемещения SetProp (progress->hDlg, L"running", (HANDLE) TRUE); // Запустить поток копирования resumeOperationThread (progress->hDlg); return 0; }