int main(int argc, char** argv) { int result = 1; RapiConnection* connection = NULL; char* source = NULL; char* dest = NULL; HRESULT hr; time_t start; time_t duration; size_t bytes_copied = 0; if (!handle_parameters(argc, argv, &source, &dest)) goto exit; if ((connection = rapi_connection_from_path(devpath)) == NULL) { fprintf(stderr, "%s: Could not find configuration at path '%s'\n", argv[0], devpath?devpath:"(Default)"); goto exit; } rapi_connection_select(connection); hr = CeRapiInit(); if (FAILED(hr)) { fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", argv[0], synce_strerror(hr)); goto exit; } if (!dest) { char* p; if (is_remote_file(source)) { for (p = source + strlen(source); p != source; p--) { if (*p == '/' || *p == '\\') { dest = strdup(p+1); break; } } if (!dest || '\0' == dest[0]) { fprintf(stderr, "%s: Unable to extract destination filename from source path '%s'\n", argv[0], source); goto exit; } } else { WCHAR mydocuments[MAX_PATH]; char* mydocuments_ascii = NULL; p = strrchr(source, '/'); if (p) p++; else p = source; if ('\0' == *p) { fprintf(stderr, "%s: Unable to extract destination filename from source path '%s'\n", argv[0], source); goto exit; } if (!CeGetSpecialFolderPath(CSIDL_PERSONAL, sizeof(mydocuments), mydocuments)) { fprintf(stderr, "%s: Unable to get the \"My Documents\" path.\n", argv[0]); goto exit; } dest = calloc(1, 1 + wstr_strlen(mydocuments) + 1 + strlen(p) + 1); mydocuments_ascii = wstr_to_current(mydocuments); strcat(dest, ":"); strcat(dest, mydocuments_ascii); strcat(dest, "\\"); strcat(dest, p); wstr_free_string(mydocuments_ascii); } } if (0 == strcmp(source, dest)) { fprintf(stderr, "You don't want to copy a file to itself.\n"); goto exit; } if (is_remote_file(source) && is_remote_file(dest)) { /* * Both are remote; use CeCopyFile() */ if (!remote_copy(source, dest)) goto exit; } else { start = time(NULL); /* * At least one is local, Use the AnyFile functions */ if (!anyfile_copy(source, dest, argv[0], &bytes_copied)) goto exit; duration = time(NULL) - start; if (0 == duration) printf("File copy took less than one second!\n"); else printf("File copy of %i bytes took %li minutes and %li seconds, that's %li bytes/s.\n", bytes_copied, duration / 60, duration % 60, bytes_copied / duration); } result = 0; exit: if (source) free(source); if (dest) free(dest); CeRapiUninit(); return result; }
bool generator_run(Generator* self) { unsigned i; bool success = false; for (i = 0; i < self->propval_count; i++) { uint16_t id = self->propvals[i].propid >> 16; GeneratorProperty* gp = (GeneratorProperty*)s_hash_table_lookup(self->properties, &id); if (gp) { if (!gp->func(self, &self->propvals[i], self->cookie)) goto exit; } else { char *tmp_str; switch (self->propvals[i].propid & 0xffff) { case CEVT_BLOB: synce_trace("Generator: Unhandled property, id: %04x, type: BLOB", id); break; case CEVT_BOOL: if (self->propvals[i].val.boolVal == FALSE) synce_trace("Generator: Unhandled property, id: %04x, type: bool:FALSE", id); else synce_trace("Generator: Unhandled property, id: %04x, type: bool:TRUE", id); break; case CEVT_FILETIME: if ((0 == self->propvals[i].val.filetime.dwLowDateTime) && (0 == self->propvals[i].val.filetime.dwHighDateTime)) synce_trace("Generator: Unhandled property, id: %04x, type: filetime:NULL", id); else { time_t start_time; char buffer[32]; parser_filetime_to_unix_time(&self->propvals[i].val.filetime, &start_time); strftime(buffer, sizeof(buffer), "%Y%m%dT%H%M%SZ", gmtime(&start_time)); synce_trace("Generator: Unhandled property, id: %04x, type: filetime:%08x %08x=%s", id, self->propvals[i].val.filetime.dwHighDateTime, self->propvals[i].val.filetime.dwLowDateTime, buffer); } break; case CEVT_I2: synce_trace("Generator: Unhandled property, id: %04x, type: I2:%d", id, self->propvals[i].val.iVal); break; case CEVT_I4: synce_trace("Generator: Unhandled property, id: %04x, type: I4:%d", id, self->propvals[i].val.iVal); break; case CEVT_LPWSTR: tmp_str = wstr_to_current(self->propvals[i].val.lpwstr); synce_trace("Generator: Unhandled property, id: %04x, type: WSTR:%s", id, tmp_str); free(tmp_str); break; case CEVT_R8: synce_trace("Generator: Unhandled property, id: %04x, type: R8", id); break; case CEVT_UI2: synce_trace("Generator: Unhandled property, id: %04x, type: UI2:%u", id, self->propvals[i].val.uiVal); break; case CEVT_UI4: synce_trace("Generator: Unhandled property, id: %04x, type: UI4:%u", id, self->propvals[i].val.uiVal); break; default: synce_trace("Generator: Unhandled property, id: %04x, unknown type: %u", id, (self->propvals[i].propid & 0xffff)); break; } } } success = true; exit: return success; }