Browse Source

Fix breaking on filenames with spaces

Bradlee Speice 7 years ago
parent
commit
d4952e4040
1 changed files with 60 additions and 48 deletions
  1. 60
    48
      libcvautomation_funcs

+ 60
- 48
libcvautomation_funcs View File

@@ -23,6 +23,11 @@
23 23
 #  an area of the screen based on an image.
24 24
 #-------------------------------------------------------------------------------
25 25
 
26
+#-------------------------------------------------------------------------------
27
+#  NOTE: Due to the way loops work in this script, you may NOT use spaces
28
+#	in file names.
29
+#-------------------------------------------------------------------------------
30
+
26 31
 #Make sure all the programs we will need are in the right place
27 32
 CVAMATCH=`which cva-match` || echo "Could not find the cva-match program..." &>2 #Needed for image recognition
28 33
 CVAINPUT=`which cva-input` || echo "Could not find the cva-input program..." &>2 #Needed to manipulate mouse and keyboard
@@ -75,9 +80,9 @@ err ()
75 80
 mouse_down ()
76 81
 {
77 82
 	if [ -n "$1" ]; then
78
-		eval $CVAINPUT -s 'mousedown $1' >> $OUTFILE >> $OUTFILE
83
+		eval $CVAINPUT -s 'mousedown "$1"' >> $OUTFILE
79 84
 	else
80
-		eval $CVAINPUT -s 'mousedown 1' >> $OUTFILE >> $OUTFILE
85
+		eval $CVAINPUT -s 'mousedown 1' >> $OUTFILE
81 86
 	fi
82 87
 	return $?
83 88
 }	# ----------  end of function mouse_down  ----------
@@ -92,9 +97,9 @@ mouse_down ()
92 97
 mouse_up ()
93 98
 {
94 99
 	if [ -n "$1" ]; then
95
-		eval $CVAINPUT -s 'mouseup $1' >> $OUTFILE >> $OUTFILE
100
+		eval $CVAINPUT -s 'mouseup "$1"' >> $OUTFILE
96 101
 	else
97
-		eval $CVAINPUT -s 'mouseup 1' >> $OUTFILE >> $OUTFILE
102
+		eval $CVAINPUT -s 'mouseup 1' >> $OUTFILE
98 103
 	fi
99 104
 	return $?
100 105
 }	# ----------  end of function mouse_up  ----------
@@ -109,9 +114,9 @@ mouse_up ()
109 114
 mouse_click ()
110 115
 {
111 116
 	if [ -n "$1" ]; then
112
-		eval '$CVAINPUT -s "mouseclick $1" >> $OUTFILE >> $OUTFILE'
117
+		eval '$CVAINPUT -s "mouseclick \"$1\"" >> $OUTFILE'
113 118
 	else
114
-		eval '$CVAINPUT -s "mouseclick 1" >> $OUTFILE >> $OUTFILE'
119
+		eval '$CVAINPUT -s "mouseclick 1" >> $OUTFILE'
115 120
 	fi
116 121
 	return $?
117 122
 }	# ----------  end of function mouse_click  ----------
@@ -137,7 +142,7 @@ mouse_click_xy ()
137 142
 		Y_LOC=$2
138 143
 	fi
139 144
 
140
-	out "click_xy: " $X_LOC $Y_LOC
145
+	out "mouse_click_xy: " $X_LOC $Y_LOC
141 146
 
142 147
 	if [ -n "$3" ]; then
143 148
 		eval '$CVAINPUT -s "mousexy $X_LOC $Y_LOC" -s "mouseclick $3" >> $OUTFILE'
@@ -171,7 +176,7 @@ mouse_click_rxy ()
171 176
 		Y_INC=$2
172 177
 	fi
173 178
 
174
-	out "clickr_xy: " $1 $2
179
+	out "mouse_click_rxy: " $1 $2
175 180
 
176 181
 	if [ -n "$3" ]; then
177 182
 		eval '$CVAINPUT -s "mouserxy $1 $2" -s "mouseclick 1" >> $OUTFILE'
@@ -198,7 +203,7 @@ mouse_click_image ()
198 203
 		return 255
199 204
 	fi
200 205
 		
201
-	out "click_i: matching $@"
206
+	out "mouse_click_image: matching $@"
202 207
 
203 208
 	if [ -n "$USE_CENTER" ]; then
204 209
 		center="c"
@@ -226,7 +231,7 @@ mouse_click_image ()
226 231
 		#I don't like this syntax, but 'for loop in {1..$OLD_TIMEOUT}' doesn't work
227 232
 		for loop in `seq 1 $OLD_TIMEOUT`
228 233
 		do
229
-			for x in $@
234
+			for x in "$@"
230 235
 			do
231 236
 					
232 237
 				CVA_RETURN=`waitfor "$x"`
@@ -238,7 +243,7 @@ mouse_click_image ()
238 243
 				if [ $CVA_RETURN -eq 0 ]; then
239 244
 					#We found the image, click it
240 245
 					TIMEOUT=$OLD_TIMEOUT
241
-					eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick $x' >> $OUTFILE"
246
+					eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick \"$x\"' >> $OUTFILE"
242 247
 					return $?
243 248
 				fi
244 249
 			done
@@ -247,7 +252,7 @@ mouse_click_image ()
247 252
 		#We'll get here if we don't find a match
248 253
 		TIMEOUT=$OLD_TIMEOUT
249 254
 	else
250
-		eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick $x' >> $OUTFILE"
255
+		eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s 'i${center}mouseclick \"$x\"' >> $OUTFILE"
251 256
 		CVA_RETURN=$?
252 257
 
253 258
 		if [ $CVA_RETURN -lt $RETURN_CODE ]; then
@@ -267,7 +272,8 @@ mouse_click_image ()
267 272
 
268 273
 mouse_rightclick_image ()
269 274
 {
270
-	hover_i $@ && click 3
275
+	out "mouse_rightclick_image: $@"
276
+	mouse_hover_image "$@" && click 3
271 277
 }	# ----------  end of function mouse_rightclick_image  ----------
272 278
 
273 279
 #---  FUNCTION  ----------------------------------------------------------------
@@ -279,10 +285,12 @@ mouse_rightclick_image ()
279 285
 
280 286
 mouse_doubleclick ()
281 287
 {
288
+	out "mouse_doubleclick: $1"
289
+
282 290
 	if [ -n "$1" ]; then
283
-		click $1 && click $1
291
+		mouse_click "$1" && mouse_click "$1"
284 292
 	else
285
-		click && click
293
+		mouse_click && mouse_click
286 294
 	fi
287 295
 }	# ----------  end of function mouse_doubleclick  ----------
288 296
 
@@ -296,24 +304,24 @@ mouse_doubleclick ()
296 304
 mouse_doubleclick_xy ()
297 305
 {
298 306
 	if [ -z "$1" ]; then
299
-		out "Did not specify an X location, assuming (0, 0)"
307
+		err "Did not specify an X location, assuming (0, 0)"
300 308
 		X_LOC=0
301 309
 		Y_LOC=0
302 310
 	else
303 311
 		X_LOC=$1
304 312
 	fi
305 313
 	if [ -z "$2" ]; then
306
-		out "Did not specify a Y location, assuming ($1, 0)"
314
+		err "Did not specify a Y location, assuming ($1, 0)"
307 315
 	else
308 316
 		Y_LOC=$2
309 317
 	fi
310 318
 
311
-	out "doubleclick_xy $X_LOC $Y_LOC"
319
+	out "mouse_doubleclick_xy $X_LOC $Y_LOC"
312 320
 
313 321
 	if [ -n "$3" ]; then
314
-		click_xy "$X_LOC" "$Y_LOC" "$3" && click "$3"
322
+		mouse_click_xy "$X_LOC" "$Y_LOC" "$3" && mouse_click "$3"
315 323
 	else
316
-		click_xy "$X_LOC" "$Y_LOC" && click
324
+		mouse_click_xy "$X_LOC" "$Y_LOC" && mouse_click
317 325
 	fi
318 326
 
319 327
 	return $?
@@ -329,25 +337,25 @@ mouse_doubleclick_xy ()
329 337
 mouse_doubleclick_rxy ()
330 338
 {
331 339
 	if [ -z "$1" ]; then
332
-		out "Did not specify an X increment, assuming (0, 0)"
340
+		err "Did not specify an X increment, assuming (0, 0)"
333 341
 		X_INC=0
334 342
 		Y_INC=0
335 343
 	else
336
-		X_INC=$1
344
+		X_INC="$1"
337 345
 	fi
338 346
 
339 347
 	if [ -z "$2" ]; then
340
-		out "Did not specify a Y increment, assuming ($X_INC, 0)"
348
+		err "Did not specify a Y increment, assuming ($X_INC, 0)"
341 349
 	else
342
-		Y_INC=$2
350
+		Y_INC="$2"
343 351
 	fi
344 352
 
345 353
 	out "doubleclickr_xy: $X_INC $Y_INC"
346 354
 
347 355
 	if [ -n "$3" ]; then
348
-		clickr_xy "$X_INC" "$Y_INC" "$3" && click "$3"
356
+		mouse_clickr_xy "$X_INC" "$Y_INC" "$3" && mouse_click "$3"
349 357
 	else
350
-		clickr_xy "$1" "$2" && click
358
+		mouse_clickr_xy "$1" "$2" && mouse_click
351 359
 	fi
352 360
 
353 361
 	return $?
@@ -364,7 +372,8 @@ mouse_doubleclick_rxy ()
364 372
 
365 373
 mouse_doubleclick_image ()
366 374
 {
367
-	hover_i "$@" && click && click
375
+	out "mouse_doubleclick_image: $@"
376
+	mouse_hover_image "$@" && mouse_click && mouse_click
368 377
 }	# ----------  end of function mouse_doubleclick_image  ----------
369 378
 
370 379
 
@@ -384,9 +393,9 @@ image_location ()
384 393
 	fi
385 394
 
386 395
 	#Build the command line arguments
387
-	for x in $@
396
+	for x in "$@"
388 397
 	do
389
-		COMMAND_LINE+="-s $x "
398
+		COMMAND_LINE+="-s \"$x\" "
390 399
 	done
391 400
 
392 401
 	#Find our sub-image
@@ -437,20 +446,20 @@ image_location ()
437 446
 mouse_hover_xy ()
438 447
 {
439 448
 	if [ -z "$1" ]; then
440
-		out "Did not provide an X location, assuming 0..."
449
+		err "Did not provide an X location, assuming 0..."
441 450
 		X_LOC=0
442 451
 	else
443 452
 		X_LOC=$1
444 453
 	fi
445 454
 
446 455
 	if [ -z "$2" ]; then
447
-		out "Did not provide a Y location, assuming 0..."
456
+		err "Did not provide a Y location, assuming 0..."
448 457
 		Y_LOC=0
449 458
 	else
450 459
 		Y_LOC=$2
451 460
 	fi
452 461
 
453
-	out "hover_xy: $X_LOC $Y_LOC"
462
+	out "mouse_hover_xy: $X_LOC $Y_LOC"
454 463
 
455 464
 	eval '$CVAINPUT -s "mousexy $X_LOC $Y_LOC" >> $OUTFILE'
456 465
 
@@ -467,20 +476,20 @@ mouse_hover_xy ()
467 476
 mouse_hover_rxy ()
468 477
 {
469 478
 	if [ -z "$1" ]; then
470
-		out "Did not provide an X increment, assuming 0..."
479
+		err "Did not provide an X increment, assuming 0..."
471 480
 		X_INC=0
472 481
 	else
473 482
 		X_INC=$1
474 483
 	fi
475 484
 
476 485
 	if [ -z "$2" ]; then
477
-		out "Did not provide a Y increment, assuming 0..."
486
+		err "Did not provide a Y increment, assuming 0..."
478 487
 		Y_INC=0
479 488
 	else
480 489
 		Y_INC=$1
481 490
 	fi
482 491
 
483
-	out "hoverr_xy: $X_INC $Y_INC"
492
+	out "mouse_hover_rxy: $X_INC $Y_INC"
484 493
 
485 494
 	eval '$CVAINPUT -s "mouserxy $X_INC $Y_INC" >> $OUTFILE'
486 495
 
@@ -530,7 +539,7 @@ mouse_hover_image ()
530 539
 		#I don't like this syntax, but 'for loop in {1..$OLD_TIMEOUT}' doesn't work
531 540
 		for loop in `seq 1 $OLD_TIMEOUT`
532 541
 		do
533
-			for x in $@
542
+			for x in "$@"
534 543
 			do
535 544
 				CVA_RETURN=`waitfor "$x"`
536 545
 
@@ -540,7 +549,7 @@ mouse_hover_image ()
540 549
 
541 550
 				if [ $CVA_RETURN -eq 0 ]; then
542 551
 					#We found the image, click it
543
-					eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s '${center}mouseimage $x' >> $OUTFILE"
552
+					eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s '${center}mouseimage \"$x\"' >> $OUTFILE"
544 553
 
545 554
 					TIMEOUT=$OLD_TIMEOUT
546 555
 					return $?
@@ -551,7 +560,7 @@ mouse_hover_image ()
551 560
 		#We'll get here if we didn't find a match
552 561
 		TIMEOUT=$OLD_TIMEOUT
553 562
 	else
554
-		eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s '${center}mouseimage $x' >> $OUTFILE"
563
+		eval "$CVAINPUT $TOLERANCE_OPTION $TOLERANCE --search-method $SEARCH_METHOD -s '${center}mouseimage \"$x\"' >> $OUTFILE"
555 564
 		CVA_RETURN=$?
556 565
 
557 566
 		if [ $CVA_RETURN -lt $RETURN_CODE ]; then
@@ -619,22 +628,22 @@ mouse_scroll_down ()
619 628
 mouse_drag_n_drop ()
620 629
 {
621 630
 	if [ -z "$1" ]; then
622
-		err "dragndrop: Did not give me an image to drag!"
631
+		err "mouse_drag_n_drop: Did not give me an image to drag!"
623 632
 		return 255
624 633
 	elif [ -z "$2" ]; then
625
-		err "dragndrop: Did not give me an image to drag to!"
634
+		err "mouse_drag_n_drop: Did not give me an image to drag to!"
626 635
 		return 255
627 636
 	fi
628 637
 
629 638
 	#We have our images to find, hover over the first, mousedown, and then
630 639
 	#hover over the other one, and mouseup.
631
-	hover_i "$1" 
640
+	mouse_hover_image "$1" 
632 641
 	if [ $? -ne 0 ]; then
633
-		err "dragndrop: Could not find image to drag!"
642
+		err "mouse_drag_n_drop: Could not find image to drag!"
634 643
 	else
635
-		mousedown 1
636
-		hover_i "$2" || err "dragndrop: Could not find image to drag to!"
637
-		mouseup
644
+		mouse_down 1
645
+		mouse_hover_image "$2" || err "mouse_drag_n_drop: Could not find image to drag to!"
646
+		mouse_up
638 647
 	fi
639 648
 }	# ----------  end of function mouse_drag_n_drop  ----------
640 649
 
@@ -653,6 +662,9 @@ key_string ()
653 662
 		return 255
654 663
 	fi
655 664
 
665
+	#We use $* instead of $@ because they expand a bit differently -
666
+	#	"$*" -> "$1 $2 $3"
667
+	#	"$@" -> "$1" "$2" "$3"
656 668
 	COMMAND_LINE="-s 'keystring $*'"
657 669
 
658 670
 	out "key_str: \"$*\""
@@ -735,18 +747,18 @@ wait_for ()
735 747
 		err "Did not give me an image to find..."
736 748
 	fi
737 749
 
738
-	out "waitfor: $1"
750
+	out "wait_for: $1"
739 751
 
740 752
 	if [ -n "$USE_SANE_TOLERANCE" ]; then
741 753
 		if [ -z "$TOLERANCE" ]; then
742 754
 			TOLERANCE=$INT_MAX
743 755
 		fi
744
-		eval '$CVAINPUT -o $TOLERANCE --search-method $SEARCH_METHOD --timeout $TIMEOUT -s "waitfor $1" >> $OUTFILE'
756
+		eval '$CVAINPUT -o $TOLERANCE --search-method $SEARCH_METHOD --timeout $TIMEOUT -s "waitfor \"$1\"" >> $OUTFILE'
745 757
 	else
746 758
 		if [ -z "$TOLERANCE" ]; then
747 759
 			TOLERANCE=$INT_MAX
748 760
 		fi
749
-		eval '$CVAINPUT -t $TOLERANCE --search-method $SEARCH_METHOD --timeout $TIMEOUT -s "waitfor $1" >> $OUTFILE'
761
+		eval '$CVAINPUT -t $TOLERANCE --search-method $SEARCH_METHOD --timeout $TIMEOUT -s "waitfor \"$1\"" >> $OUTFILE'
750 762
 	fi
751 763
 
752 764
 	RETURN_CODE=$?

Loading…
Cancel
Save