void ElBaseCommand::insertElement() { if(NULL != _element) { // insert the command at the parent index. QList<int> pathPos(path); int lastPos = pathPos.last(); pathPos.removeLast(); Element *parentElement = NULL ; if(!pathPos.isEmpty()) { parentElement = regola->findElementByArray(pathPos); } _lastOpElement = regola->insertInternal(widget, parentElement, _element, lastPos); if(_selectParent && (NULL != parentElement)) { widget->setCurrentItem(parentElement->getUI()); } loseElement(); } }
void ElBaseCommand::insertElementObj(Element *element, const bool isUndo) { if(NULL != _element) { // insert the command at the parent index. QList<int> pathPos(path); int lastPos = pathPos.last(); pathPos.removeLast(); Element *parentElement = NULL ; if(!pathPos.isEmpty()) { parentElement = regola->findElementByArray(pathPos); } _lastOpElement = regola->insertInternal(widget, parentElement, element, lastPos); if(NULL != _lastOpElement) { widget->setCurrentItem(_lastOpElement->getUI()); } if(_selectParent && (NULL != parentElement)) { widget->setCurrentItem(parentElement->getUI()); } if(!isUndo && _hilite && (NULL != _lastOpElement)) { _lastOpElement->hilite(); } } }
void ElBaseCommand::updateElementObj(Element *current, Element *newValue, const bool isUndo) { if(NULL != _element) { // insert the command at the parent index. QList<int> pathPos(path); pathPos.removeLast(); Element *parentElement = NULL ; if(!pathPos.isEmpty()) { parentElement = regola->findElementByArray(pathPos); } newValue->copyTo(*current, false); _lastOpElement = current ; regola->updateElementUI(current); if(NULL != current) { widget->setCurrentItem(current->getUI()); } if(_selectParent && (NULL != parentElement)) { widget->setCurrentItem(parentElement->getUI()); } if(!isUndo && _hilite && (NULL != current)) { current->hilite(); } } }
int main(int argc, char *argv[]) { int opt = 0; #ifdef __WIN32__ WSADATA WsaDat; #endif if ( argc < 2 ) { dispInfo(argv[0]); exit(0); } #ifdef __WIN32__ WSAStartup(MAKEWORD(2,2),&WsaDat); #endif if ( !strnicmp(argv[1], "-p", 2) ) // reset cpc { startCard(argv[2]); } else if ( !strnicmp(argv[1], "-r", 2) ) // reboot M4 { reset(argv[2]); } else if ( !strnicmp(argv[1], "-s", 2) ) // reset cpc { resetCPC(argv[2]); } else if ( !strnicmp(argv[1], "-x", 2) && (argc>=3) ) // execute { run(argv[2], argv[3]); } else if ( !strnicmp(argv[1], "-f", 2) && (argc>=4) ) // upload (flash) rom { uploadRom(argv[3], argv[2], atoi(argv[4]), argv[5] ); } else if ( !strnicmp(argv[1], "-u", 2) && (argc>=4) ) // upload { unsigned short start = 0; unsigned short exec = 0; if ( argc < 5 ) { dispInfo(argv[0]); exit(0); } if ( argc>5 ) { opt = atoi(argv[5]); if ( opt == 2 ) // add binary header ? { // we need more parameters then if ( argc < 8 ) { printf("Please add start address and exec. address for binary header\r\n"); exit(0); } start = atoh(argv[6]); exec = atoh(argv[7]); } } upload(argv[3], argv[4], argv[2], opt, start, exec); } else if ( !strnicmp(argv[1], "-c", 2) && (argc>=4) ) // upload cartridge { uploadctr(argv[3], argv[2]); } else if ( !strnicmp(argv[1], "-y", 2) && (argc>=3) ) { // Prepare the file manipulation variables char fullpath[256]; char path[] = "/tmp"; // TODO Find a way to use /tmp or something like that char * filename = argv[3]; char * ip = argv[2]; int p = pathPos(filename, strlen(filename)); // strip any PC path from filename sprintf(fullpath, "%s/%s", path, &filename[p]); upload(filename, path, ip, 0, 0, 0 ); // Upload the file on CPC run(ip, fullpath); // Execute the file on CPC } else if ( !strnicmp(argv[1], "-d", 2) && (argc>=4) ) // download { if ( argc>5 ) opt = atoi(argv[5]); download(argv[3], argv[4], argv[2], opt); } else { dispInfo(argv[0]); exit(0); } #ifdef __WIN32__ WSACleanup(); #endif return 0; }
void upload(char *filename, char *path, char *ip, int opt, unsigned short start, unsigned short exec) { int ret, size, p, n, k, i, j; char fullpath[256]; // don't exceed this, the cpc wouldn't be able |cd it anyway FILE *fd; SOCKET sd; unsigned char *buf; fd = fopen(filename, "rb"); if ( fd == NULL ) { printf("file %s not found\n", filename); return; } #ifndef __WIN32__ if (!is_regular_file(filename)) { printf("file %s is not a regular file\n", filename); fclose(fd); return; } #endif fseek(fd, 0, SEEK_END); size = ftell(fd); fseek(fd, 0, SEEK_SET); buf = malloc(size+0x80); if ( buf == NULL ) { printf("Not enough memory!\n"); fclose(fd); return; } if ( opt != 0 ) { _cpchead *cpcheader = (_cpchead *)buf; memset(cpcheader, 0, 0x80); // set up cleaned filename and extionsion formatfn(cpcheader->filename, filename); getExtension(cpcheader->extension, filename); // add more file types here... and more paramters.... switch (opt) { case 1: cpcheader->addr = 0x172; // protext uses this cpcheader->type = 10; cpcheader->size = size; cpcheader->size2 = size; cpcheader->checksum = checksum16(buf, 66); break; default: case 2: // binary header cpcheader->addr = start; cpcheader->exec = exec; cpcheader->type = 2; cpcheader->size = size; cpcheader->size2 = size; cpcheader->checksum = checksum16(buf, 66); break; } fread(&buf[0x80], size, 1, fd); size+=0x80; } else fread(buf, size, 1, fd); fclose(fd); ret = httpConnect(ip); if ( ret >= 0 ) { sd = ret; // connect socket p = pathPos(filename, strlen(filename)); // strip any PC path from filename sprintf(fullpath, "%s/%s", path, &filename[p]); k = strlen(fullpath); n = 0; while ( n < k ) // remove leading / from path { if ( fullpath[n] != '/' ) break; n++; } // remove duplicate /'s k = strlen(fullpath); j = 0; for (i=n; i < (k+1); i++) { if ( (fullpath[i] == '/') && (fullpath[i+1] == '/') ) i++; fullpath[j++] = fullpath[i]; } if ( httpSend(sd, fullpath, buf, size, "upfile", "/upload.html", ip) >= 0 ) ret = httpResponse(sd); httpClose(sd); if ( ret == 200 ) printf("Upload OK!\r\n"); else printf("Upload error code. %i\r\n", ret); } else printf("Connect to %s failed\n", ip); free(buf); }